From e4fe8c836751596f048afb85ee6cd60a0ccf0811 Mon Sep 17 00:00:00 2001 From: Roland Lammel Date: Thu, 17 Dec 2020 02:07:41 +0100 Subject: [PATCH] Fix failing tests on systems not supporting IPv6 --- echo_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/echo_test.go b/echo_test.go index a6071e12a..29edca107 100644 --- a/echo_test.go +++ b/echo_test.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io/ioutil" + "net" "net/http" "net/http/httptest" "reflect" @@ -730,8 +731,24 @@ var listenerNetworkTests = []struct { {"tcp6 ipv6 address", "tcp6", "[::1]:1323"}, } +func supportsIPv6() bool { + addrs, _ := net.InterfaceAddrs() + for _, addr := range addrs { + // Check if any interface has local IPv6 assigned + if strings.Contains(addr.String(), "::1") { + return true + } + } + return false +} + func TestEchoListenerNetwork(t *testing.T) { + hasIPv6 := supportsIPv6() for _, tt := range listenerNetworkTests { + if !hasIPv6 && strings.Contains(tt.address, "::") { + t.Skip("Skipping testing IPv6 for " + tt.address + ", not available") + continue + } t.Run(tt.test, func(t *testing.T) { e := New() e.ListenerNetwork = tt.network