summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/miekg/dns/clientconfig_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/miekg/dns/clientconfig_test.go')
-rw-r--r--vendor/github.com/miekg/dns/clientconfig_test.go54
1 files changed, 51 insertions, 3 deletions
diff --git a/vendor/github.com/miekg/dns/clientconfig_test.go b/vendor/github.com/miekg/dns/clientconfig_test.go
index 4c5d1fb60..5c10360d7 100644
--- a/vendor/github.com/miekg/dns/clientconfig_test.go
+++ b/vendor/github.com/miekg/dns/clientconfig_test.go
@@ -40,6 +40,28 @@ func testConfig(t *testing.T, data string) {
func TestNameserver(t *testing.T) { testConfig(t, normal) }
func TestMissingFinalNewLine(t *testing.T) { testConfig(t, missingNewline) }
+func TestNdots(t *testing.T) {
+ ndotsVariants := map[string]int{
+ "options ndots:0": 0,
+ "options ndots:1": 1,
+ "options ndots:15": 15,
+ "options ndots:16": 15,
+ "options ndots:-1": 0,
+ "": 1,
+ }
+
+ for data := range ndotsVariants {
+ cc, err := ClientConfigFromReader(strings.NewReader(data))
+ if err != nil {
+ t.Errorf("error parsing resolv.conf: %v", err)
+ }
+ if cc.Ndots != ndotsVariants[data] {
+ t.Errorf("Ndots not properly parsed: (Expected: %d / Was: %d)", ndotsVariants[data], cc.Ndots)
+ }
+ }
+
+}
+
func TestReadFromFile(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
if err != nil {
@@ -67,7 +89,7 @@ func TestReadFromFile(t *testing.T) {
}
}
-func TestNameList(t *testing.T) {
+func TestNameListNdots1(t *testing.T) {
cfg := ClientConfig{
Ndots: 1,
}
@@ -91,10 +113,18 @@ func TestNameList(t *testing.T) {
} else if names[1] != "miek.nl.test." {
t.Errorf("NameList didn't return search last: %v", names[1])
}
+}
+func TestNameListNdots2(t *testing.T) {
+ cfg := ClientConfig{
+ Ndots: 2,
+ }
- cfg.Ndots = 2
// Sent domain has less than NDots and search
- names = cfg.NameList("miek.nl")
+ cfg.Search = []string{
+ "test",
+ }
+ names := cfg.NameList("miek.nl")
+
if len(names) != 2 {
t.Errorf("NameList returned != 2 names: %v", names)
} else if names[0] != "miek.nl.test." {
@@ -103,3 +133,21 @@ func TestNameList(t *testing.T) {
t.Errorf("NameList didn't return sent domain last: %v", names[1])
}
}
+
+func TestNameListNdots0(t *testing.T) {
+ cfg := ClientConfig{
+ Ndots: 0,
+ }
+ cfg.Search = []string{
+ "test",
+ }
+ // Sent domain has less than NDots and search
+ names := cfg.NameList("miek")
+ if len(names) != 2 {
+ t.Errorf("NameList returned != 2 names: %v", names)
+ } else if names[0] != "miek." {
+ t.Errorf("NameList didn't return search first: %v", names[0])
+ } else if names[1] != "miek.test." {
+ t.Errorf("NameList didn't return sent domain last: %v", names[1])
+ }
+}