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/
pull/6/head
Daniel Martí 2015-08-21 22:20:47 -07:00
parent 0b10c6cfae
commit 7aca60f636
1 changed files with 16 additions and 5 deletions

View File

@ -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) {
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)
} }
} }
} }