Created
December 15, 2018 15:57
-
-
Save bgadrian/92e51f4b2d9b32893ec8f95c40327e3a to your computer and use it in GitHub Desktop.
Fake a HTTP Request/Client.Do response w/o a webserver.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type recordingTransport struct { | |
req *http.Request | |
} | |
func (t *recordingTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) { | |
t.req = req | |
return &http.Response{ | |
Body: ioutil.NopCloser(bytes.NewBufferString("alfa")), | |
}, nil | |
} | |
func TestNewScraper(t *testing.T) { | |
client = &http.Client{ | |
Timeout: time.Millisecond * 10, | |
Transport: &recordingTransport{}, | |
} | |
request, _ := http.NewRequest("", "http://dummy.faketld/", nil) | |
resp := Client.Do(request) | |
//respBody will be "alfa" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment