1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Copyright 2013 Canonical Ltd. This software is licensed under the
// GNU Lesser General Public License version 3 (see the file COPYING).
package gwacl
import (
"fmt"
. "launchpad.net/gocheck"
"net/http"
)
type testTesting struct{}
var _ = Suite(&testTesting{})
func (suite *testTesting) TestNewTestStorageContext(c *C) {
errorMessage := "canned-error"
error := fmt.Errorf(errorMessage)
transport := &TestTransport{Error: error}
client := &http.Client{Transport: transport}
context := NewTestStorageContext(client)
request := &ListContainersRequest{Marker: ""}
_, err := context.ListContainers(request)
c.Check(err, ErrorMatches, ".*"+errorMessage+".*")
}
func (suite *testTesting) TestNewDispatcherResponse(c *C) {
body := []byte("test body")
statusCode := http.StatusOK
errorObject := fmt.Errorf("canned-error")
dispatcherResponse := NewDispatcherResponse(body, statusCode, errorObject)
c.Check(dispatcherResponse.errorObject, Equals, errorObject)
c.Check(dispatcherResponse.response.Body, DeepEquals, body)
c.Check(dispatcherResponse.response.StatusCode, Equals, statusCode)
}
func (suite *testTesting) TestPatchManagementAPIResponses(c *C) {
response := NewDispatcherResponse([]byte("<Images></Images>"), http.StatusOK, nil)
responses := []DispatcherResponse{response, response}
requests := PatchManagementAPIResponses(responses)
api := makeAPI(c)
_, err := api.ListOSImages()
c.Assert(err, IsNil)
_, err = api.ListOSImages()
c.Assert(err, IsNil)
c.Assert(len(*requests), Equals, 2)
c.Check((*requests)[0].URL, Equals, api.session.composeURL("services/images"))
c.Check((*requests)[1].URL, Equals, api.session.composeURL("services/images"))
}
|