Commit 7aca60f6 authored by Daniel Martí's avatar Daniel Martí

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/
parent 0b10c6cf
...@@ -29,17 +29,28 @@ import ( ...@@ -29,17 +29,28 @@ import (
"k8s.io/kubernetes/pkg/probe" "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) { func TestTcpHealthChecker(t *testing.T) {
prober := New() prober := New()
tests := []struct { tests := []struct {
expectedStatus probe.Result expectedStatus probe.Result
usePort bool usePort bool
expectError 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. // The probe will be filled in below. This is primarily testing that a connection is made.
{probe.Success, true, false, ""}, {probe.Success, true, false, []string{""}},
{probe.Failure, false, false, "tcp: unknown port"}, {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) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
...@@ -72,8 +83,8 @@ func TestTcpHealthChecker(t *testing.T) { ...@@ -72,8 +83,8 @@ func TestTcpHealthChecker(t *testing.T) {
if err == nil && test.expectError { if err == nil && test.expectError {
t.Errorf("unexpected non-error.") t.Errorf("unexpected non-error.")
} }
if !strings.Contains(output, test.output) { if !containsAny(output, test.accOutputs) {
t.Errorf("expected %s, got %s", test.output, output) t.Errorf("expected one of %#v, got %s", test.accOutputs, output)
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment