~rvb/gwacl/image-fix

« back to all changes in this revision

Viewing changes to storage_test.go

  • Committer: Tarmac
  • Author(s): Jeroen Vermeulen
  • Date: 2013-04-25 02:31:28 UTC
  • mfrom: (93.2.1 extract-roundtrippers)
  • Revision ID: tarmac-20130425023128-n8nag1qdnmfghlz9
[r=rvb][bug=][author=jtv] Extract a bunch of our test helpers into separate files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import (
7
7
    "bytes"
8
 
    "encoding/base64"
9
8
    "fmt"
10
9
    "io/ioutil"
11
10
    . "launchpad.net/gocheck"
13
12
    "net/url"
14
13
)
15
14
 
16
 
func b64(s string) string {
17
 
    return base64.StdEncoding.EncodeToString([]byte(s))
18
 
}
19
 
 
20
 
type TestTransport2Exchange struct {
21
 
    Request  *http.Request
22
 
    Response *http.Response
23
 
    Error    error
24
 
}
25
 
 
26
 
// TestTransport2 is used as an http.Client.Transport for testing. The only
27
 
// requirement is that it adhere to the http.RoundTripper interface.
28
 
type TestTransport2 struct {
29
 
    Exchanges     []*TestTransport2Exchange
30
 
    ExchangeCount int
31
 
}
32
 
 
33
 
func (t *TestTransport2) AddExchange(response *http.Response, error error) {
34
 
    exchange := TestTransport2Exchange{Response: response, Error: error}
35
 
    t.Exchanges = append(t.Exchanges, &exchange)
36
 
}
37
 
 
38
 
func (t *TestTransport2) RoundTrip(req *http.Request) (resp *http.Response, err error) {
39
 
    exchange := t.Exchanges[t.ExchangeCount]
40
 
    t.ExchangeCount += 1
41
 
    exchange.Request = req
42
 
    return exchange.Response, exchange.Error
43
 
}
44
 
 
45
15
type testUploadBlockBlob struct{}
46
16
 
47
17
var _ = Suite(&testUploadBlockBlob{})
87
57
    assertBlockListSent(c, context, []string{b64("0"), b64("1")}, transport.Exchanges[2])
88
58
}
89
59
 
90
 
func makeFakeCreatedResponse() *http.Response {
91
 
    return &http.Response{
92
 
        Status:     fmt.Sprintf("%d", http.StatusCreated),
93
 
        StatusCode: http.StatusCreated,
94
 
        Body:       Empty,
95
 
    }
96
 
}
97
 
 
98
60
func uploadRandomBlob(c *C, context *StorageContext, size int) []byte {
99
61
    data := MakeRandomByteSlice(size)
100
62
    err := context.UploadBlockBlob(