Files
zhuangang/topics/devops/docker/examples/go-api-compose/main_test.go
T

23 lines
449 B
Go

package main
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestRoutes(t *testing.T) {
srv := httptest.NewServer(newMux())
defer srv.Close()
for path, want := range map[string]int{"/healthz": 200, "/api/hello": 200, "/nope": 404} {
resp, err := http.Get(srv.URL + path)
if err != nil {
t.Fatal(err)
}
resp.Body.Close()
if resp.StatusCode != want {
t.Errorf("%s = %d, want %d", path, resp.StatusCode, want)
}
}
}