Commit ed7cd254 authored by Mikio Hara's avatar Mikio Hara

net: make use of internal/testenv package

Change-Id: I6644081df495cb92b3d208f867066f9acb08946f
Reviewed-on: https://go-review.googlesource.com/22074
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 8f64336e
......@@ -24,13 +24,12 @@ var prohibitionaryDialArgTests = []struct {
}
func TestProhibitionaryDialArg(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
switch runtime.GOOS {
case "plan9":
t.Skipf("not supported on %s", runtime.GOOS)
}
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
if !supportsIPv4map {
t.Skip("mapping ipv4 address inside ipv6 address not supported")
}
......@@ -243,9 +242,8 @@ func dialClosedPort() (actual, expected time.Duration) {
}
func TestDialParallel(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
if !supportsIPv4 || !supportsIPv6 {
t.Skip("both IPv4 and IPv6 are required")
}
......@@ -422,9 +420,8 @@ func lookupSlowFast(fn func(string) ([]IPAddr, error), host string) ([]IPAddr, e
}
func TestDialerFallbackDelay(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
if !supportsIPv4 || !supportsIPv6 {
t.Skip("both IPv4 and IPv6 are required")
}
......@@ -814,18 +811,18 @@ func TestDialerKeepAlive(t *testing.T) {
}
func TestDialCancel(t *testing.T) {
switch testenv.Builder() {
case "linux-arm64-buildlet":
t.Skip("skipping on linux-arm64-buildlet; incompatible network config? issue 15191")
case "":
testenv.MustHaveExternalNetwork(t)
}
if runtime.GOOS == "plan9" || runtime.GOOS == "nacl" {
// plan9 is not implemented and nacl doesn't have
// external network access.
t.Skipf("skipping on %s", runtime.GOOS)
}
onGoBuildFarm := testenv.Builder() != ""
if testing.Short() && !onGoBuildFarm {
t.Skip("skipping in short mode")
}
if testenv.Builder() == "linux-arm64-buildlet" {
t.Skip("skipping on linux-arm64-buildlet; incompatible network config? issue 15191")
}
blackholeIPPort := JoinHostPort(slowDst4, "1234")
if !supportsIPv4 {
......
......@@ -8,6 +8,7 @@ package net
import (
"fmt"
"internal/testenv"
"io/ioutil"
"os"
"path"
......@@ -32,9 +33,7 @@ var dnsTransportFallbackTests = []struct {
}
func TestDNSTransportFallback(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
for _, tt := range dnsTransportFallbackTests {
timeout := time.Duration(tt.timeout) * time.Second
......@@ -74,9 +73,7 @@ var specialDomainNameTests = []struct {
}
func TestSpecialDomainName(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
server := "8.8.8.8:53"
for _, tt := range specialDomainNameTests {
......@@ -232,9 +229,7 @@ var updateResolvConfTests = []struct {
}
func TestUpdateResolvConf(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
conf, err := newResolvConfTest()
if err != nil {
......@@ -389,9 +384,7 @@ var goLookupIPWithResolverConfigTests = []struct {
}
func TestGoLookupIPWithResolverConfig(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
conf, err := newResolvConfTest()
if err != nil {
......@@ -436,9 +429,7 @@ func TestGoLookupIPWithResolverConfig(t *testing.T) {
// Test that goLookupIPOrder falls back to the host file when no DNS servers are available.
func TestGoLookupIPOrderFallbackToFile(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
// Add a config that simulates no dns servers being available.
conf, err := newResolvConfTest()
......
......@@ -6,15 +6,15 @@ package net
import (
"fmt"
"internal/testenv"
"io"
"strings"
"testing"
)
func TestResolveGoogle(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
if !supportsIPv4 || !supportsIPv6 || !*testIPv4 || !*testIPv6 {
t.Skip("both IPv4 and IPv6 are required")
}
......@@ -60,9 +60,8 @@ var dialGoogleTests = []struct {
}
func TestDialGoogle(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
if !supportsIPv4 || !supportsIPv6 || !*testIPv4 || !*testIPv6 {
t.Skip("both IPv4 and IPv6 are required")
}
......
......@@ -8,6 +8,7 @@ package net
import (
"fmt"
"internal/testenv"
"os"
"runtime"
"syscall"
......@@ -483,13 +484,12 @@ func checkDualStackAddrFamily(fd *netFD) error {
}
func TestWildWildcardListener(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
switch runtime.GOOS {
case "plan9":
t.Skipf("not supported on %s", runtime.GOOS)
}
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
defer func() {
if p := recover(); p != nil {
......@@ -527,12 +527,17 @@ var ipv4MulticastListenerTests = []struct {
// test listener with same address family, same group address and same
// port.
func TestIPv4MulticastListener(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
switch runtime.GOOS {
case "android", "nacl", "plan9":
t.Skipf("not supported on %s", runtime.GOOS)
case "solaris":
t.Skipf("not supported on solaris, see golang.org/issue/7399")
}
if !supportsIPv4 {
t.Skip("IPv4 is not supported")
}
closer := func(cs []*UDPConn) {
for _, c := range cs {
......@@ -548,7 +553,7 @@ func TestIPv4MulticastListener(t *testing.T) {
// routing stuff for finding out an appropriate
// nexthop containing both network and link layer
// adjacencies.
if ifi == nil && (testing.Short() || !*testExternal) {
if ifi == nil || !*testIPv4 {
continue
}
for _, tt := range ipv4MulticastListenerTests {
......@@ -597,6 +602,8 @@ var ipv6MulticastListenerTests = []struct {
// test listener with same address family, same group address and same
// port.
func TestIPv6MulticastListener(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
switch runtime.GOOS {
case "plan9":
t.Skipf("not supported on %s", runtime.GOOS)
......@@ -604,7 +611,7 @@ func TestIPv6MulticastListener(t *testing.T) {
t.Skipf("not supported on solaris, see issue 7399")
}
if !supportsIPv6 {
t.Skip("ipv6 is not supported")
t.Skip("IPv6 is not supported")
}
if os.Getuid() != 0 {
t.Skip("must be root")
......@@ -624,7 +631,7 @@ func TestIPv6MulticastListener(t *testing.T) {
// routing stuff for finding out an appropriate
// nexthop containing both network and link layer
// adjacencies.
if ifi == nil && (testing.Short() || !*testExternal || !*testIPv6) {
if ifi == nil && !*testIPv6 {
continue
}
for _, tt := range ipv6MulticastListenerTests {
......
......@@ -58,9 +58,10 @@ var lookupGoogleSRVTests = []struct {
}
func TestLookupGoogleSRV(t *testing.T) {
if testing.Short() && testenv.Builder() == "" || !*testExternal {
t.Skip("avoid external network")
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !*testIPv4 {
t.Skip("IPv4 is required")
}
......@@ -92,9 +93,10 @@ var lookupGmailMXTests = []struct {
}
func TestLookupGmailMX(t *testing.T) {
if testing.Short() && testenv.Builder() == "" || !*testExternal {
t.Skip("avoid external network")
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !*testIPv4 {
t.Skip("IPv4 is required")
}
......@@ -123,9 +125,10 @@ var lookupGmailNSTests = []struct {
}
func TestLookupGmailNS(t *testing.T) {
if testing.Short() && testenv.Builder() == "" || !*testExternal {
t.Skip("avoid external network")
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !*testIPv4 {
t.Skip("IPv4 is required")
}
......@@ -154,9 +157,10 @@ var lookupGmailTXTTests = []struct {
}
func TestLookupGmailTXT(t *testing.T) {
if testing.Short() && testenv.Builder() == "" || !*testExternal {
t.Skip("avoid external network")
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !*testIPv4 {
t.Skip("IPv4 is required")
}
......@@ -188,9 +192,10 @@ var lookupGooglePublicDNSAddrTests = []struct {
}
func TestLookupGooglePublicDNSAddr(t *testing.T) {
if testing.Short() && testenv.Builder() == "" || !*testExternal {
t.Skip("avoid external network")
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !supportsIPv6 || !*testIPv4 || !*testIPv6 {
t.Skip("both IPv4 and IPv6 are required")
}
......@@ -243,9 +248,10 @@ var lookupIANACNAMETests = []struct {
}
func TestLookupIANACNAME(t *testing.T) {
if testing.Short() && testenv.Builder() == "" || !*testExternal {
t.Skip("avoid external network")
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !*testIPv4 {
t.Skip("IPv4 is required")
}
......@@ -269,9 +275,10 @@ var lookupGoogleHostTests = []struct {
}
func TestLookupGoogleHost(t *testing.T) {
if testing.Short() && testenv.Builder() == "" || !*testExternal {
t.Skip("avoid external network")
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !*testIPv4 {
t.Skip("IPv4 is required")
}
......@@ -300,9 +307,10 @@ var lookupGoogleIPTests = []struct {
}
func TestLookupGoogleIP(t *testing.T) {
if testing.Short() && testenv.Builder() == "" || !*testExternal {
t.Skip("avoid external network")
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !*testIPv4 {
t.Skip("IPv4 is required")
}
......@@ -463,9 +471,10 @@ func TestLookupDotsWithLocalSource(t *testing.T) {
}
func TestLookupDotsWithRemoteSource(t *testing.T) {
if testing.Short() && testenv.Builder() == "" || !*testExternal {
t.Skip("avoid external network")
if testenv.Builder() == "" {
testenv.MustHaveExternalNetwork(t)
}
if !supportsIPv4 || !*testIPv4 {
t.Skip("IPv4 is required")
}
......
......@@ -8,6 +8,7 @@ import (
"bytes"
"encoding/json"
"errors"
"internal/testenv"
"os/exec"
"reflect"
"regexp"
......@@ -24,9 +25,7 @@ func toJson(v interface{}) string {
}
func TestLookupMX(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
for _, server := range nslookupTestServers {
mx, err := LookupMX(server)
......@@ -51,9 +50,7 @@ func TestLookupMX(t *testing.T) {
}
func TestLookupCNAME(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
for _, server := range nslookupTestServers {
cname, err := LookupCNAME(server)
......@@ -76,9 +73,7 @@ func TestLookupCNAME(t *testing.T) {
}
func TestLookupNS(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
for _, server := range nslookupTestServers {
ns, err := LookupNS(server)
......@@ -104,9 +99,7 @@ func TestLookupNS(t *testing.T) {
}
func TestLookupTXT(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
for _, server := range nslookupTestServers {
txt, err := LookupTXT(server)
......
......@@ -26,8 +26,6 @@ var (
var (
testDNSFlood = flag.Bool("dnsflood", false, "whether to test DNS query flooding")
testExternal = flag.Bool("external", true, "allow use of external networks during long test")
// If external IPv4 connectivity exists, we can try dialing
// non-node/interface local scope IPv4 addresses.
// On Windows, Lookup APIs may not return IPv4-related
......
......@@ -5,6 +5,7 @@
package net
import (
"internal/testenv"
"os"
"runtime"
"strings"
......@@ -110,7 +111,7 @@ func testableListenArgs(network, address, client string) bool {
}
// Test wildcard IP addresses.
if wildcard && (testing.Short() || !*testExternal) {
if wildcard && !testenv.HasExternalNetwork() {
return false
}
......
......@@ -5,6 +5,7 @@
package net
import (
"internal/testenv"
"io"
"reflect"
"runtime"
......@@ -345,9 +346,7 @@ var tcpListenerNameTests = []struct {
}
func TestTCPListenerName(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
for _, tt := range tcpListenerNameTests {
ln, err := ListenTCP(tt.net, tt.laddr)
......@@ -363,9 +362,8 @@ func TestTCPListenerName(t *testing.T) {
}
func TestIPv6LinkLocalUnicastTCP(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
if !supportsIPv6 {
t.Skip("IPv6 is not supported")
}
......
......@@ -5,6 +5,7 @@
package net
import (
"internal/testenv"
"reflect"
"runtime"
"testing"
......@@ -178,9 +179,7 @@ var udpConnLocalNameTests = []struct {
}
func TestUDPConnLocalName(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
for _, tt := range udpConnLocalNameTests {
c, err := ListenUDP(tt.net, tt.laddr)
......@@ -234,9 +233,8 @@ func TestUDPConnLocalAndRemoteNames(t *testing.T) {
}
func TestIPv6LinkLocalUnicastUDP(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("avoid external network")
}
testenv.MustHaveExternalNetwork(t)
if !supportsIPv6 {
t.Skip("IPv6 is not supported")
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment