Skip to content

Fix failing tests on systems not supporting IPv6 #1725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
"reflect"
Expand Down Expand Up @@ -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
Expand Down