diff options
Diffstat (limited to 'libgo/go/net/lookup_test.go')
-rw-r--r-- | libgo/go/net/lookup_test.go | 85 |
1 files changed, 77 insertions, 8 deletions
diff --git a/libgo/go/net/lookup_test.go b/libgo/go/net/lookup_test.go index b3aeb85afbc..36db56acd03 100644 --- a/libgo/go/net/lookup_test.go +++ b/libgo/go/net/lookup_test.go @@ -243,14 +243,15 @@ func TestLookupIPv6LinkLocalAddr(t *testing.T) { } } -var lookupIANACNAMETests = []struct { +var lookupCNAMETests = []struct { name, cname string }{ {"www.iana.org", "icann.org."}, {"www.iana.org.", "icann.org."}, + {"www.google.com", "google.com."}, } -func TestLookupIANACNAME(t *testing.T) { +func TestLookupCNAME(t *testing.T) { if testenv.Builder() == "" { testenv.MustHaveExternalNetwork(t) } @@ -259,7 +260,7 @@ func TestLookupIANACNAME(t *testing.T) { t.Skip("IPv4 is required") } - for _, tt := range lookupIANACNAMETests { + for _, tt := range lookupCNAMETests { cname, err := LookupCNAME(tt.name) if err != nil { t.Fatal(err) @@ -398,11 +399,11 @@ func TestDNSFlood(t *testing.T) { for i := 0; i < N; i++ { name := fmt.Sprintf("%d.net-test.golang.org", i) go func() { - _, err := lookupIPContext(ctxHalfTimeout, name) + _, err := DefaultResolver.LookupIPAddr(ctxHalfTimeout, name) c <- err }() go func() { - _, err := lookupIPContext(ctxTimeout, name) + _, err := DefaultResolver.LookupIPAddr(ctxTimeout, name) c <- err }() } @@ -616,7 +617,7 @@ func srvString(srvs []*SRV) string { func TestLookupPort(t *testing.T) { // See http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml // - // Please be careful about adding new mappings for testings. + // Please be careful about adding new test cases. // There are platforms having incomplete mappings for // restricted resource access and security reasons. type test struct { @@ -648,8 +649,6 @@ func TestLookupPort(t *testing.T) { } switch runtime.GOOS { - case "nacl": - t.Skipf("not supported on %s", runtime.GOOS) case "android": if netGo { t.Skipf("not supported on %s without cgo; see golang.org/issues/14576", runtime.GOOS) @@ -670,3 +669,73 @@ func TestLookupPort(t *testing.T) { } } } + +// Like TestLookupPort but with minimal tests that should always pass +// because the answers are baked-in to the net package. +func TestLookupPort_Minimal(t *testing.T) { + type test struct { + network string + name string + port int + } + var tests = []test{ + {"tcp", "http", 80}, + {"tcp", "HTTP", 80}, // case shouldn't matter + {"tcp", "https", 443}, + {"tcp", "ssh", 22}, + {"tcp", "gopher", 70}, + {"tcp4", "http", 80}, + {"tcp6", "http", 80}, + } + + for _, tt := range tests { + port, err := LookupPort(tt.network, tt.name) + if port != tt.port || err != nil { + t.Errorf("LookupPort(%q, %q) = %d, %v; want %d, error=nil", tt.network, tt.name, port, err, tt.port) + } + } +} + +func TestLookupProtocol_Minimal(t *testing.T) { + type test struct { + name string + want int + } + var tests = []test{ + {"tcp", 6}, + {"TcP", 6}, // case shouldn't matter + {"icmp", 1}, + {"igmp", 2}, + {"udp", 17}, + {"ipv6-icmp", 58}, + } + + for _, tt := range tests { + got, err := lookupProtocol(context.Background(), tt.name) + if got != tt.want || err != nil { + t.Errorf("LookupProtocol(%q) = %d, %v; want %d, error=nil", tt.name, got, err, tt.want) + } + } + +} + +func TestLookupNonLDH(t *testing.T) { + if runtime.GOOS == "nacl" { + t.Skip("skip on nacl") + } + if fixup := forceGoDNS(); fixup != nil { + defer fixup() + } + + // "LDH" stands for letters, digits, and hyphens and is the usual + // description of standard DNS names. + // This test is checking that other kinds of names are reported + // as not found, not reported as invalid names. + addrs, err := LookupHost("!!!.###.bogus..domain.") + if err == nil { + t.Fatalf("lookup succeeded: %v", addrs) + } + if !strings.HasSuffix(err.Error(), errNoSuchHost.Error()) { + t.Fatalf("lookup error = %v, want %v", err, errNoSuchHost) + } +} |