Merge lp:~rvb/gwacl/expose-testing-utility into lp:gwacl

Proposed by Raphaël Badin on 2013-07-08
Status: Merged
Approved by: Raphaël Badin on 2013-07-08
Approved revision: 167
Merged at revision: 167
Proposed branch: lp:~rvb/gwacl/expose-testing-utility
Merge into: lp:gwacl
Diff against target: 80 lines (+31/-31)
2 files modified
helpers_http_test.go (+0/-31)
testing.go (+31/-0)
To merge this branch: bzr merge lp:~rvb/gwacl/expose-testing-utility
Reviewer Review Type Date Requested Status
Gavin Panella 2013-07-08 Approve on 2013-07-08
Review via email: mp+173452@code.launchpad.net

Commit message

Expose MockingTransport and MockingTransportExchange.

Description of the change

This branch simply moves the definitions of MockingTransportExchange and MockingTransport in testing.go so that they can be used by third-party application with the need to test complex scenarios (i.e. when a single method in the third-party application issues more that one request to the Azure API through gwacl).

To post a comment you must log in.
Gavin Panella (allenap) wrote :

Looks good. At some point we ought to consider moving some of these parts into separate namespaces, but that time is not now :)

review: Approve
Raphaël Badin (rvb) wrote :

> Looks good. At some point we ought to consider moving some of these parts into
> separate namespaces, but that time is not now :)

Thanks for the review!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'helpers_http_test.go'
2--- helpers_http_test.go 2013-07-02 04:21:04 +0000
3+++ helpers_http_test.go 2013-07-08 10:04:25 +0000
4@@ -30,37 +30,6 @@
5 return t.Response, t.Error
6 }
7
8-// MockingTransportExchange is a recording of a request and a response over
9-// HTTP.
10-type MockingTransportExchange struct {
11- Request *http.Request
12- Response *http.Response
13- Error error
14-}
15-
16-// MockingTransport is used as an http.Client.Transport for testing. It
17-// records the sequence of requests, and returns a predetermined sequence of
18-// Responses and errors.
19-type MockingTransport struct {
20- Exchanges []*MockingTransportExchange
21- ExchangeCount int
22-}
23-
24-// MockingTransport implements the http.RoundTripper interface.
25-var _ http.RoundTripper = &MockingTransport{}
26-
27-func (t *MockingTransport) AddExchange(response *http.Response, error error) {
28- exchange := MockingTransportExchange{Response: response, Error: error}
29- t.Exchanges = append(t.Exchanges, &exchange)
30-}
31-
32-func (t *MockingTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
33- exchange := t.Exchanges[t.ExchangeCount]
34- t.ExchangeCount += 1
35- exchange.Request = req
36- return exchange.Response, exchange.Error
37-}
38-
39 // makeFakeCreatedResponse returns an HTTP response with the Created status.
40 func makeFakeCreatedResponse() *http.Response {
41 return &http.Response{
42
43=== modified file 'testing.go'
44--- testing.go 2013-06-27 13:58:43 +0000
45+++ testing.go 2013-07-08 10:04:25 +0000
46@@ -43,3 +43,34 @@
47 },
48 errorObject: errorObject}
49 }
50+
51+// MockingTransport is used as an http.Client.Transport for testing. It
52+// records the sequence of requests, and returns a predetermined sequence of
53+// Responses and errors.
54+type MockingTransport struct {
55+ Exchanges []*MockingTransportExchange
56+ ExchangeCount int
57+}
58+
59+// MockingTransport implements the http.RoundTripper interface.
60+var _ http.RoundTripper = &MockingTransport{}
61+
62+func (t *MockingTransport) AddExchange(response *http.Response, error error) {
63+ exchange := MockingTransportExchange{Response: response, Error: error}
64+ t.Exchanges = append(t.Exchanges, &exchange)
65+}
66+
67+func (t *MockingTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
68+ exchange := t.Exchanges[t.ExchangeCount]
69+ t.ExchangeCount += 1
70+ exchange.Request = req
71+ return exchange.Response, exchange.Error
72+}
73+
74+// MockingTransportExchange is a recording of a request and a response over
75+// HTTP.
76+type MockingTransportExchange struct {
77+ Request *http.Request
78+ Response *http.Response
79+ Error error
80+}

Subscribers

People subscribed via source and target branches

to all changes: