You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

28 lines
775 B

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
}