From 0b10c6cfae0853935c571aa5f1b16128ca88950d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 21 Aug 2015 16:00:44 -0700 Subject: [PATCH] Fix failing test in probe/http The error that Go 1.5 returns is different compared to 1.4. Support both. --- pkg/probe/http/http_test.go | 40 +++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/pkg/probe/http/http_test.go b/pkg/probe/http/http_test.go index 987f3103f88..65cd0398282 100644 --- a/pkg/probe/http/http_test.go +++ b/pkg/probe/http/http_test.go @@ -29,6 +29,15 @@ import ( "k8s.io/kubernetes/pkg/probe" ) +func containsAny(s string, substrs []string) bool { + for _, substr := range substrs { + if strings.Contains(s, substr) { + return true + } + } + return false +} + func TestHTTPProbeChecker(t *testing.T) { handleReq := func(s int, body string) func(w http.ResponseWriter) { return func(w http.ResponseWriter) { @@ -41,12 +50,31 @@ func TestHTTPProbeChecker(t *testing.T) { testCases := []struct { handler func(w http.ResponseWriter) health probe.Result - body string + // go1.5: error message changed for timeout, need to support + // both old and new + accBodies []string }{ // The probe will be filled in below. This is primarily testing that an HTTP GET happens. - {handleReq(http.StatusOK, "ok body"), probe.Success, "ok body"}, - {handleReq(-1, "fail body"), probe.Failure, "fail body"}, - {func(w http.ResponseWriter) { time.Sleep(3 * time.Second) }, probe.Failure, "use of closed network connection"}, + { + handleReq(http.StatusOK, "ok body"), + probe.Success, + []string{"ok body"}, + }, + { + handleReq(-1, "fail body"), + probe.Failure, + []string{"fail body"}, + }, + { + func(w http.ResponseWriter) { + time.Sleep(3 * time.Second) + }, + probe.Failure, + []string{ + "use of closed network connection", + "request canceled (Client.Timeout exceeded while awaiting headers)", + }, + }, } for _, test := range testCases { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -74,8 +102,8 @@ func TestHTTPProbeChecker(t *testing.T) { if health != test.health { t.Errorf("Expected %v, got %v", test.health, health) } - if !strings.Contains(output, test.body) { - t.Errorf("Expected %v, got %v", test.body, output) + if !containsAny(output, test.accBodies) { + t.Errorf("Expected one of %#v, got %v", test.accBodies, output) } } }