Alex Brainman | 5da14d1 | 2011-08-05 10:27:51 +1000 | [diff] [blame] | 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. |
| 4 | |
| 5 | // TODO It would be nice to use a mock DNS server, to eliminate |
| 6 | // external dependencies. |
| 7 | |
| 8 | package net |
| 9 | |
| 10 | import ( |
| 11 | "runtime" |
| 12 | "testing" |
| 13 | ) |
| 14 | |
| 15 | var avoidMacFirewall = runtime.GOOS == "darwin" |
| 16 | |
| 17 | func TestGoogleSRV(t *testing.T) { |
| 18 | if testing.Short() || avoidMacFirewall { |
| 19 | t.Logf("skipping test to avoid external network") |
| 20 | return |
| 21 | } |
| 22 | _, addrs, err := LookupSRV("xmpp-server", "tcp", "google.com") |
| 23 | if err != nil { |
| 24 | t.Errorf("failed: %s", err) |
| 25 | } |
| 26 | if len(addrs) == 0 { |
| 27 | t.Errorf("no results") |
| 28 | } |
Russ Cox | 48bb3e8 | 2011-10-18 13:57:04 -0400 | [diff] [blame] | 29 | |
| 30 | // Non-standard back door. |
| 31 | _, addrs, err = LookupSRV("", "", "_xmpp-server._tcp.google.com") |
| 32 | if err != nil { |
| 33 | t.Errorf("back door failed: %s", err) |
| 34 | } |
| 35 | if len(addrs) == 0 { |
| 36 | t.Errorf("back door no results") |
| 37 | } |
Alex Brainman | 5da14d1 | 2011-08-05 10:27:51 +1000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | func TestGmailMX(t *testing.T) { |
| 41 | if testing.Short() || avoidMacFirewall { |
| 42 | t.Logf("skipping test to avoid external network") |
| 43 | return |
| 44 | } |
| 45 | mx, err := LookupMX("gmail.com") |
| 46 | if err != nil { |
| 47 | t.Errorf("failed: %s", err) |
| 48 | } |
| 49 | if len(mx) == 0 { |
| 50 | t.Errorf("no results") |
| 51 | } |
| 52 | } |
| 53 | |
Nigel Tao | 40d85fb | 2011-09-13 13:05:33 +1000 | [diff] [blame] | 54 | func TestGmailTXT(t *testing.T) { |
Nigel Tao | 40d85fb | 2011-09-13 13:05:33 +1000 | [diff] [blame] | 55 | if testing.Short() || avoidMacFirewall { |
| 56 | t.Logf("skipping test to avoid external network") |
| 57 | return |
| 58 | } |
| 59 | txt, err := LookupTXT("gmail.com") |
| 60 | if err != nil { |
| 61 | t.Errorf("failed: %s", err) |
| 62 | } |
| 63 | if len(txt) == 0 || len(txt[0]) == 0 { |
| 64 | t.Errorf("no results") |
| 65 | } |
| 66 | } |
| 67 | |
Alex Brainman | 5da14d1 | 2011-08-05 10:27:51 +1000 | [diff] [blame] | 68 | func TestGoogleDNSAddr(t *testing.T) { |
| 69 | if testing.Short() || avoidMacFirewall { |
| 70 | t.Logf("skipping test to avoid external network") |
| 71 | return |
| 72 | } |
| 73 | names, err := LookupAddr("8.8.8.8") |
| 74 | if err != nil { |
| 75 | t.Errorf("failed: %s", err) |
| 76 | } |
| 77 | if len(names) == 0 { |
| 78 | t.Errorf("no results") |
| 79 | } |
| 80 | } |