diff options
Diffstat (limited to 'vendor/github.com/miekg/dns/clientconfig_test.go')
-rw-r--r-- | vendor/github.com/miekg/dns/clientconfig_test.go | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/vendor/github.com/miekg/dns/clientconfig_test.go b/vendor/github.com/miekg/dns/clientconfig_test.go index 7755a8a6f..4c5d1fb60 100644 --- a/vendor/github.com/miekg/dns/clientconfig_test.go +++ b/vendor/github.com/miekg/dns/clientconfig_test.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "testing" ) @@ -20,6 +21,26 @@ nameserver 10.28.10.2 nameserver 11.28.10.1` // <- NOTE: NO newline. func testConfig(t *testing.T, data string) { + cc, err := ClientConfigFromReader(strings.NewReader(data)) + if err != nil { + t.Errorf("error parsing resolv.conf: %v", err) + } + if l := len(cc.Servers); l != 2 { + t.Errorf("incorrect number of nameservers detected: %d", l) + } + if l := len(cc.Search); l != 1 { + t.Errorf("domain directive not parsed correctly: %v", cc.Search) + } else { + if cc.Search[0] != "somedomain.com" { + t.Errorf("domain is unexpected: %v", cc.Search[0]) + } + } +} + +func TestNameserver(t *testing.T) { testConfig(t, normal) } +func TestMissingFinalNewLine(t *testing.T) { testConfig(t, missingNewline) } + +func TestReadFromFile(t *testing.T) { tempDir, err := ioutil.TempDir("", "") if err != nil { t.Fatalf("tempDir: %v", err) @@ -27,7 +48,7 @@ func testConfig(t *testing.T, data string) { defer os.RemoveAll(tempDir) path := filepath.Join(tempDir, "resolv.conf") - if err := ioutil.WriteFile(path, []byte(data), 0644); err != nil { + if err := ioutil.WriteFile(path, []byte(normal), 0644); err != nil { t.Fatalf("writeFile: %v", err) } cc, err := ClientConfigFromFile(path) @@ -46,9 +67,6 @@ func testConfig(t *testing.T, data string) { } } -func TestNameserver(t *testing.T) { testConfig(t, normal) } -func TestMissingFinalNewLine(t *testing.T) { testConfig(t, missingNewline) } - func TestNameList(t *testing.T) { cfg := ClientConfig{ Ndots: 1, |