Verify request success while testing http requests
This commit is contained in:
@@ -9,10 +9,14 @@ import (
|
|||||||
func testRequest(targetUrl string, expectedResponse string) {
|
func testRequest(targetUrl string, expectedResponse string) {
|
||||||
resp, err := http.Get(targetUrl)
|
resp, err := http.Get(targetUrl)
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
log.Panic("failed make get request")
|
log.Panicf("failed to make get request: %v", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if (resp.StatusCode != 200) {
|
||||||
|
log.Panicf("response status: %v", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
log.Panic("failed to read response")
|
log.Panic("failed to read response")
|
||||||
|
|||||||
Reference in New Issue
Block a user