Merge pull request #6720 from fabiofalci/relax_dns_search

Relax dns search to accept empty domain
This commit is contained in:
Victor Vieux 2014-07-07 15:12:29 -07:00
commit b4ab982c97
2 changed files with 29 additions and 2 deletions

View file

@ -78,10 +78,12 @@ func Build(path string, dns, dnsSearch []string) error {
}
}
if len(dnsSearch) > 0 {
if _, err := content.WriteString("search " + strings.Join(dnsSearch, " ") + "\n"); err != nil {
if searchString := strings.Join(dnsSearch, " "); strings.Trim(searchString, " ") != "." {
if _, err := content.WriteString("search " + searchString + "\n"); err != nil {
return err
}
}
}
return ioutil.WriteFile(path, content.Bytes(), 0644)
}

View file

@ -131,3 +131,28 @@ func TestBuild(t *testing.T) {
t.Fatalf("Expected to find '%s' got '%s'", expected, content)
}
}
func TestBuildWithZeroLengthDomainSearch(t *testing.T) {
file, err := ioutil.TempFile("", "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(file.Name())
err = Build(file.Name(), []string{"ns1", "ns2", "ns3"}, []string{"."})
if err != nil {
t.Fatal(err)
}
content, err := ioutil.ReadFile(file.Name())
if err != nil {
t.Fatal(err)
}
if expected := "nameserver ns1\nnameserver ns2\nnameserver ns3\n"; !bytes.Contains(content, []byte(expected)) {
t.Fatalf("Expected to find '%s' got '%s'", expected, content)
}
if notExpected := "search ."; bytes.Contains(content, []byte(notExpected)) {
t.Fatalf("Expected to not find '%s' got '%s'", notExpected, content)
}
}