Files
fission-src/pkg/router/util_test.go
T
Eng Zer JunandGitHub 2f4ec4b2b9 refactor: move from io/ioutil to io and os package (#2236)
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-10-23 17:14:12 +05:30

37 lines
657 B
Go

package router
import (
"io"
"log"
"net/http"
)
func testRequest(targetURL string, expectedResponse string) {
resp, err := http.Get(targetURL)
if err != nil {
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 := io.ReadAll(resp.Body)
if err != nil {
log.Panic("failed to read response")
}
bodyStr := string(body)
log.Printf("Server responded with %v", bodyStr)
if bodyStr != expectedResponse {
log.Panic("Unexpected response")
}
}
func panicIf(err error) {
if err != nil {
log.Panicf("Error: %v", err)
}
}