diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-10-30 19:02:50 +0100 |
|---|---|---|
| committer | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-10-30 19:02:50 +0100 |
| commit | 2d3cd6584dedce45ea709d1757a28ce7537f3472 (patch) | |
| tree | c21ce25cd66731c56b3fd13c86734bd13ebd7d25 /utils.go | |
| parent | 2bfae5b426bf4a0b99d3979ed12d63cb50c39b17 (diff) | |
Refactor to prepare for builtin JS functions
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 +} |