summaryrefslogtreecommitdiff
path: root/utils.go
diff options
context:
space:
mode:
authorPhilipp Tanlak <philipp.tanlak@gmail.com>2023-10-30 19:02:50 +0100
committerPhilipp Tanlak <philipp.tanlak@gmail.com>2023-10-30 19:02:50 +0100
commit2d3cd6584dedce45ea709d1757a28ce7537f3472 (patch)
treec21ce25cd66731c56b3fd13c86734bd13ebd7d25 /utils.go
parent2bfae5b426bf4a0b99d3979ed12d63cb50c39b17 (diff)
Refactor to prepare for builtin JS functions
Diffstat (limited to 'utils.go')
-rw-r--r--utils.go16
1 files changed, 16 insertions, 0 deletions
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
+}