From 7aca60f636ecaf43c2246f1d4767b2a333257083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 21 Aug 2015 22:20:47 -0700 Subject: [PATCH] Fix probe/tcp test on some systems Depending on your system, the error might be "Servname not supported for ai_socktype" instead of "unknown port". Accept both. For example: http://www.ducea.com/2006/09/11/error-servname-not-supported-for-ai_socktype/ --- pkg/probe/tcp/tcp_test.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pkg/probe/tcp/tcp_test.go b/pkg/probe/tcp/tcp_test.go index d30f088a78..8b4c80e03c 100644 --- a/pkg/probe/tcp/tcp_test.go +++ b/pkg/probe/tcp/tcp_test.go @@ -29,17 +29,28 @@ 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 TestTcpHealthChecker(t *testing.T) { prober := New() tests := []struct { expectedStatus probe.Result usePort bool expectError bool - output string + // Some errors are different depending on your system, make + // the test pass on all of them + accOutputs []string }{ // The probe will be filled in below. This is primarily testing that a connection is made. - {probe.Success, true, false, ""}, - {probe.Failure, false, false, "tcp: unknown port"}, + {probe.Success, true, false, []string{""}}, + {probe.Failure, false, false, []string{"unknown port", "Servname not supported for ai_socktype"}}, } server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -72,8 +83,8 @@ func TestTcpHealthChecker(t *testing.T) { if err == nil && test.expectError { t.Errorf("unexpected non-error.") } - if !strings.Contains(output, test.output) { - t.Errorf("expected %s, got %s", test.output, output) + if !containsAny(output, test.accOutputs) { + t.Errorf("expected one of %#v, got %s", test.accOutputs, output) } } }