test: Add handleHealth method tests
Add 2 tests for health endpoint: - POST/PUT/DELETE/PATCH return 405 Method Not Allowed - HEAD is allowed (same as GET) Coverage: 50% → 83.3%
This commit is contained in:
parent
2d09c28129
commit
de90519b21
1 changed files with 40 additions and 0 deletions
|
|
@ -350,6 +350,46 @@ func TestServerInfoEndpointMethodNotAllowed(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestHealthEndpointMethodNotAllowed(t *testing.T) {
|
||||
srv := newIntegrationServer(t)
|
||||
|
||||
for _, method := range []string{http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch} {
|
||||
req, err := http.NewRequest(method, srv.server.URL+"/api/health", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("create request failed: %v", err)
|
||||
}
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("health %s request failed: %v", method, err)
|
||||
}
|
||||
res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusMethodNotAllowed {
|
||||
t.Errorf("%s: unexpected status: got %d want %d", method, res.StatusCode, http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthEndpointHeadAllowed(t *testing.T) {
|
||||
srv := newIntegrationServer(t)
|
||||
|
||||
req, err := http.NewRequest(http.MethodHead, srv.server.URL+"/api/health", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("create request failed: %v", err)
|
||||
}
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("health HEAD request failed: %v", err)
|
||||
}
|
||||
res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
t.Fatalf("HEAD: unexpected status: got %d want %d", res.StatusCode, http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigNodesUsesMockTopology(t *testing.T) {
|
||||
srv := newIntegrationServer(t)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue