summaryrefslogtreecommitdiff
path: root/mock.go
diff options
context:
space:
mode:
Diffstat (limited to 'mock.go')
-rw-r--r--mock.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/mock.go b/mock.go
new file mode 100644
index 0000000..44b8837
--- /dev/null
+++ b/mock.go
@@ -0,0 +1,22 @@
+package flyscrape
+
+import (
+ "fmt"
+ "io"
+ "net/http"
+ "strings"
+)
+
+func MockTransport(statusCode int, html string) func(*http.Request) (*http.Response, error) {
+ 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
+}