mirror of https://github.com/matrix-org/go-neb.git
Browse Source
Merge pull request #129 from matrix-org/kegan/testutils
Merge pull request #129 from matrix-org/kegan/testutils
Add a dedicated testutils packagepull/131/head
Kegsay
8 years ago
committed by
GitHub
4 changed files with 43 additions and 39 deletions
-
18src/github.com/matrix-org/go-neb/services/guggy/guggy_test.go
-
18src/github.com/matrix-org/go-neb/services/rssbot/rssbot_test.go
-
18src/github.com/matrix-org/go-neb/services/travisci/travisci_test.go
-
28src/github.com/matrix-org/go-neb/testutils/testutils.go
@ -0,0 +1,28 @@ |
|||
package testutils |
|||
|
|||
import ( |
|||
"net/http" |
|||
) |
|||
|
|||
// MockTransport implements RoundTripper
|
|||
type MockTransport struct { |
|||
// RT is the RoundTrip function. Replace this function with your test function.
|
|||
// For example:
|
|||
// t := MockTransport{}
|
|||
// t.RT = func(req *http.Request) (*http.Response, error) {
|
|||
// // assert req args, return res or error
|
|||
// }
|
|||
RT func(*http.Request) (*http.Response, error) |
|||
} |
|||
|
|||
// RoundTrip is a RoundTripper
|
|||
func (t MockTransport) RoundTrip(req *http.Request) (*http.Response, error) { |
|||
return t.RT(req) |
|||
} |
|||
|
|||
// NewRoundTripper returns a new RoundTripper which will call the provided function.
|
|||
func NewRoundTripper(roundTrip func(*http.Request) (*http.Response, error)) http.RoundTripper { |
|||
rt := MockTransport{} |
|||
rt.RT = roundTrip |
|||
return rt |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue