diff options
Diffstat (limited to 'utils.go')
| -rw-r--r-- | utils.go | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -7,6 +7,8 @@ package flyscrape import ( "bytes" "encoding/json" + "fmt" + "io" "net/http" "strings" ) @@ -25,3 +27,17 @@ type RoundTripFunc func(*http.Request) (*http.Response, error) func (f RoundTripFunc) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) } + +func MockTransport(statusCode int, html string) RoundTripFunc { + return func(*http.Request) (*http.Response, error) { + return MockResponse(statusCode, html) + } +} + +func MockResponse(statusCode int, html string) (*http.Response, error) { + return &http.Response{ + StatusCode: statusCode, + Status: fmt.Sprintf("%d %s", statusCode, http.StatusText(statusCode)), + Body: io.NopCloser(strings.NewReader(html)), + }, nil +} |