1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Fix failing tests on systems not supporting IPv6

This commit is contained in:
Roland Lammel 2020-12-17 02:07:41 +01:00
parent 829e82165f
commit e4fe8c8367

View File

@ -6,6 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"reflect" "reflect"
@ -730,8 +731,24 @@ var listenerNetworkTests = []struct {
{"tcp6 ipv6 address", "tcp6", "[::1]:1323"}, {"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) { func TestEchoListenerNetwork(t *testing.T) {
hasIPv6 := supportsIPv6()
for _, tt := range listenerNetworkTests { 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) { t.Run(tt.test, func(t *testing.T) {
e := New() e := New()
e.ListenerNetwork = tt.network e.ListenerNetwork = tt.network