speedy/pkg/testing/http.go
Denis-Cosmin Nutiu 64256f57cc initial commit
2021-10-04 14:03:36 +03:00

18 lines
476 B
Go

package testing
import "net/http"
// RoundTripFunc is a mock for testing httpClient
type RoundTripFunc func(req *http.Request) *http.Response
// RoundTrip is a mock for testing httpClient
func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req), nil
}
//NewTestClient returns *http.Client with Transport replaced to avoid making real calls
func NewTestClient(fn RoundTripFunc) *http.Client {
return &http.Client{
Transport: fn,
}
}