Verify request success while testing http requests

This commit is contained in:
Soam Vasani
2016-09-01 14:34:56 -07:00
parent 9bd586ce61
commit 322ca405f6
+5 -1
View File
@@ -9,10 +9,14 @@ import (
func testRequest(targetUrl string, expectedResponse string) {
resp, err := http.Get(targetUrl)
if (err != nil) {
log.Panic("failed make get request")
log.Panicf("failed to make get request: %v", err)
}
defer resp.Body.Close()
if (resp.StatusCode != 200) {
log.Panicf("response status: %v", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
if (err != nil) {
log.Panic("failed to read response")