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

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
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 Approve
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.
Revision history for this message
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
Revision history for this message
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
=== modified file 'helpers_http_test.go'
--- helpers_http_test.go 2013-07-02 04:21:04 +0000
+++ helpers_http_test.go 2013-07-08 10:04:25 +0000
@@ -30,37 +30,6 @@
30 return t.Response, t.Error30 return t.Response, t.Error
31}31}
3232
33// MockingTransportExchange is a recording of a request and a response over
34// HTTP.
35type MockingTransportExchange struct {
36 Request *http.Request
37 Response *http.Response
38 Error error
39}
40
41// MockingTransport is used as an http.Client.Transport for testing. It
42// records the sequence of requests, and returns a predetermined sequence of
43// Responses and errors.
44type MockingTransport struct {
45 Exchanges []*MockingTransportExchange
46 ExchangeCount int
47}
48
49// MockingTransport implements the http.RoundTripper interface.
50var _ http.RoundTripper = &MockingTransport{}
51
52func (t *MockingTransport) AddExchange(response *http.Response, error error) {
53 exchange := MockingTransportExchange{Response: response, Error: error}
54 t.Exchanges = append(t.Exchanges, &exchange)
55}
56
57func (t *MockingTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
58 exchange := t.Exchanges[t.ExchangeCount]
59 t.ExchangeCount += 1
60 exchange.Request = req
61 return exchange.Response, exchange.Error
62}
63
64// makeFakeCreatedResponse returns an HTTP response with the Created status.33// makeFakeCreatedResponse returns an HTTP response with the Created status.
65func makeFakeCreatedResponse() *http.Response {34func makeFakeCreatedResponse() *http.Response {
66 return &http.Response{35 return &http.Response{
6736
=== modified file 'testing.go'
--- testing.go 2013-06-27 13:58:43 +0000
+++ testing.go 2013-07-08 10:04:25 +0000
@@ -43,3 +43,34 @@
43 },43 },
44 errorObject: errorObject}44 errorObject: errorObject}
45}45}
46
47// MockingTransport is used as an http.Client.Transport for testing. It
48// records the sequence of requests, and returns a predetermined sequence of
49// Responses and errors.
50type MockingTransport struct {
51 Exchanges []*MockingTransportExchange
52 ExchangeCount int
53}
54
55// MockingTransport implements the http.RoundTripper interface.
56var _ http.RoundTripper = &MockingTransport{}
57
58func (t *MockingTransport) AddExchange(response *http.Response, error error) {
59 exchange := MockingTransportExchange{Response: response, Error: error}
60 t.Exchanges = append(t.Exchanges, &exchange)
61}
62
63func (t *MockingTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
64 exchange := t.Exchanges[t.ExchangeCount]
65 t.ExchangeCount += 1
66 exchange.Request = req
67 return exchange.Response, exchange.Error
68}
69
70// MockingTransportExchange is a recording of a request and a response over
71// HTTP.
72type MockingTransportExchange struct {
73 Request *http.Request
74 Response *http.Response
75 Error error
76}

Subscribers

People subscribed via source and target branches

to all changes: