From 2d3cd6584dedce45ea709d1757a28ce7537f3472 Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Mon, 30 Oct 2023 19:02:50 +0100 Subject: Refactor to prepare for builtin JS functions --- utils.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'utils.go') diff --git a/utils.go b/utils.go index faa4937..161cff8 100644 --- a/utils.go +++ b/utils.go @@ -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 +} -- cgit v1.2.3