mirror of https://github.com/matrix-org/go-neb.git
Browse Source
Add a dedicated testutils package
Add a dedicated testutils package
In the spirit of "if you have to do something 3 times then factor it out", make a testutils package to put all the `RoundTrip` boilerplate. I don't overly like having test packages, especially mixed in with code, but I don't see a nicer way of doing this without ending up with a sprawling mess of copypasta'd test boilerplate which will be an absolute nightmare to maintain. I think this is the lesser of two evils.pull/129/head
Kegan Dougal
8 years ago
4 changed files with 30 additions and 36 deletions
-
17src/github.com/matrix-org/go-neb/services/guggy/guggy_test.go
-
17src/github.com/matrix-org/go-neb/services/rssbot/rssbot_test.go
-
17src/github.com/matrix-org/go-neb/services/travisci/travisci_test.go
-
15src/github.com/matrix-org/go-neb/testutils/testutils.go
@ -0,0 +1,15 @@ |
|||||
|
package testutils |
||||
|
|
||||
|
import ( |
||||
|
"net/http" |
||||
|
) |
||||
|
|
||||
|
// MockTransport implements RoundTripper
|
||||
|
type MockTransport struct { |
||||
|
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) |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue