diff --git a/staging/src/k8s.io/apiserver/pkg/server/healthz/healthz_test.go b/staging/src/k8s.io/apiserver/pkg/server/healthz/healthz_test.go index a1f761b786b..7ae26c4e9ce 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/healthz/healthz_test.go +++ b/staging/src/k8s.io/apiserver/pkg/server/healthz/healthz_test.go @@ -74,20 +74,20 @@ func TestInstallPathHandler(t *testing.T) { } -func TestMulitipleChecks(t *testing.T) { +func testMultipleChecks(path string, t *testing.T) { tests := []struct { path string expectedResponse string expectedStatus int addBadCheck bool }{ - {"/healthz?verbose", "[+]ping ok\nhealthz check passed\n", http.StatusOK, false}, - {"/healthz/ping", "ok", http.StatusOK, false}, - {"/healthz", "ok", http.StatusOK, false}, - {"/healthz?verbose", "[+]ping ok\n[-]bad failed: reason withheld\nhealthz check failed\n", http.StatusInternalServerError, true}, - {"/healthz/ping", "ok", http.StatusOK, true}, - {"/healthz/bad", "internal server error: this will fail\n", http.StatusInternalServerError, true}, - {"/healthz", "[+]ping ok\n[-]bad failed: reason withheld\nhealthz check failed\n", http.StatusInternalServerError, true}, + {"?verbose", "[+]ping ok\nhealthz check passed\n", http.StatusOK, false}, + {"/ping", "ok", http.StatusOK, false}, + {"", "ok", http.StatusOK, false}, + {"?verbose", "[+]ping ok\n[-]bad failed: reason withheld\nhealthz check failed\n", http.StatusInternalServerError, true}, + {"/ping", "ok", http.StatusOK, true}, + {"/bad", "internal server error: this will fail\n", http.StatusInternalServerError, true}, + {"", "[+]ping ok\n[-]bad failed: reason withheld\nhealthz check failed\n", http.StatusInternalServerError, true}, } for i, test := range tests { @@ -98,8 +98,13 @@ func TestMulitipleChecks(t *testing.T) { return errors.New("this will fail") })) } - InstallHandler(mux, checks...) - req, err := http.NewRequest("GET", fmt.Sprintf("http://example.com%v", test.path), nil) + if path == "" { + InstallHandler(mux, checks...) + path = "/healthz" + } else { + InstallPathHandler(mux, path, checks...) + } + req, err := http.NewRequest("GET", fmt.Sprintf("http://example.com%s%v", path, test.path), nil) if err != nil { t.Fatalf("case[%d] Unexpected error: %v", i, err) } @@ -114,6 +119,14 @@ func TestMulitipleChecks(t *testing.T) { } } +func TestMultipleChecks(t *testing.T) { + testMultipleChecks("", t) +} + +func TestMultiplePathChecks(t *testing.T) { + testMultipleChecks("/ready", t) +} + func TestCheckerNames(t *testing.T) { n1 := "n1" n2 := "n2"