mirror of https://github.com/k3s-io/k3s
Merge pull request #64100 from JacobTanenbaum/InstallPathHandler-tests
Automatic merge from submit-queue (batch tested with PRs 63580, 63744, 64541, 64502, 64100). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Improve unit tests for InstallPathHandler() When adding InstallPathHandler it was suggested to follow-up with an improvement to the unit tests. deads2k suggested that the testing for InstallPathHandler() follow closer to what is already implemented for InstallHandler(). **What this PR does / why we need it**: Increases the testing around new functionality InstallPathHandler **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```pull/8/head
commit
27c327cd33
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue