From 5ee71afca3cee0de47c4cca2ff510ac6b5c3782d Mon Sep 17 00:00:00 2001 From: Salman Aljammaz Date: Mon, 21 Oct 2013 21:20:43 +0100 Subject: [PATCH] auth: don't fail IPv6 test if host can't resolve localhost to [::1] Change-Id: I3eade17e593da67d33be86563fe179ac6464c561 --- pkg/auth/auth_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/auth/auth_test.go b/pkg/auth/auth_test.go index f8e922894..eeab660d8 100644 --- a/pkg/auth/auth_test.go +++ b/pkg/auth/auth_test.go @@ -104,7 +104,26 @@ func TestLocalhostAuthIPv6(t *testing.T) { } testLoginRequest(t, &http.Client{Transport: trans}, "http://[::1]:"+port) - testLoginRequest(t, &http.Client{Transport: trans}, "http://localhost:"+port) + + // See if we can get an IPv6 from resolving localhost + localips, err := net.LookupIP("localhost") + if err != nil { + t.Skipf("skipping IPv6 test; resolving localhost failed with %v", err) + } + if hasIPv6(localips) { + testLoginRequest(t, &http.Client{Transport: trans}, "http://localhost:"+port) + } else { + t.Logf("incomplete IPv6 test; resolving localhost didn't return any IPv6 addresses") + } +} + +func hasIPv6(ips []net.IP) bool { + for _, ip := range ips { + if ip.To4() == nil { + return true + } + } + return false } func TestLocalhostAuthIPv4(t *testing.T) {