1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // TODO It would be nice to use a mock DNS server, to eliminate
6 // external dependencies.
15 var testExternal = flag.Bool("external", true, "allow use of external networks during long test")
17 func TestGoogleSRV(t *testing.T) {
18 if testing.Short() || !*testExternal {
19 t.Logf("skipping test to avoid external network")
22 _, addrs, err := LookupSRV("xmpp-server", "tcp", "google.com")
24 t.Errorf("failed: %s", err)
27 t.Errorf("no results")
30 // Non-standard back door.
31 _, addrs, err = LookupSRV("", "", "_xmpp-server._tcp.google.com")
33 t.Errorf("back door failed: %s", err)
36 t.Errorf("back door no results")
40 func TestGmailMX(t *testing.T) {
41 if testing.Short() || !*testExternal {
42 t.Logf("skipping test to avoid external network")
45 mx, err := LookupMX("gmail.com")
47 t.Errorf("failed: %s", err)
50 t.Errorf("no results")
54 func TestGmailTXT(t *testing.T) {
55 if testing.Short() || !*testExternal {
56 t.Logf("skipping test to avoid external network")
59 txt, err := LookupTXT("gmail.com")
61 t.Errorf("failed: %s", err)
63 if len(txt) == 0 || len(txt[0]) == 0 {
64 t.Errorf("no results")
68 func TestGoogleDNSAddr(t *testing.T) {
69 if testing.Short() || !*testExternal {
70 t.Logf("skipping test to avoid external network")
73 names, err := LookupAddr("8.8.8.8")
75 t.Errorf("failed: %s", err)
78 t.Errorf("no results")
82 var revAddrTests = []struct {
87 {"1.2.3.4", "4.3.2.1.in-addr.arpa.", ""},
88 {"245.110.36.114", "114.36.110.245.in-addr.arpa.", ""},
89 {"::ffff:12.34.56.78", "78.56.34.12.in-addr.arpa.", ""},
90 {"::1", "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.", ""},
91 {"1::", "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.ip6.arpa.", ""},
92 {"1234:567::89a:bcde", "e.d.c.b.a.9.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.7.6.5.0.4.3.2.1.ip6.arpa.", ""},
93 {"1234:567:fefe:bcbc:adad:9e4a:89a:bcde", "e.d.c.b.a.9.8.0.a.4.e.9.d.a.d.a.c.b.c.b.e.f.e.f.7.6.5.0.4.3.2.1.ip6.arpa.", ""},
94 {"1.2.3", "", "unrecognized address"},
95 {"1.2.3.4.5", "", "unrecognized address"},
96 {"1234:567:bcbca::89a:bcde", "", "unrecognized address"},
97 {"1234:567::bcbc:adad::89a:bcde", "", "unrecognized address"},
100 func TestReverseAddress(t *testing.T) {
101 for i, tt := range revAddrTests {
102 a, err := reverseaddr(tt.Addr)
103 if len(tt.ErrPrefix) > 0 && err == nil {
104 t.Errorf("#%d: expected %q, got <nil> (error)", i, tt.ErrPrefix)
107 if len(tt.ErrPrefix) == 0 && err != nil {
108 t.Errorf("#%d: expected <nil>, got %q (error)", i, err)
110 if err != nil && err.(*DNSError).Err != tt.ErrPrefix {
111 t.Errorf("#%d: expected %q, got %q (mismatched error)", i, tt.ErrPrefix, err.(*DNSError).Err)
114 t.Errorf("#%d: expected %q, got %q (reverse address)", i, tt.Reverse, a)