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>
37 lines
657 B
Go
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)
|
|
}
|
|
}
|