1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
package net
import (
"reflect"
"testing"
)
var dnsReadConfigTests = []struct {
name string
conf dnsConfig
}{
{
name: "testdata/resolv.conf",
conf: dnsConfig{
servers: []string{"8.8.8.8", "2001:4860:4860::8888", "fe80::1%lo0"},
search: []string{"localdomain"},
ndots: 5,
timeout: 10,
attempts: 3,
rotate: true,
},
},
{
name: "testdata/domain-resolv.conf",
conf: dnsConfig{
servers: []string{"8.8.8.8"},
search: []string{"localdomain"},
ndots: 1,
timeout: 5,
attempts: 2,
},
},
{
name: "testdata/search-resolv.conf",
conf: dnsConfig{
servers: []string{"8.8.8.8"},
search: []string{"test", "invalid"},
ndots: 1,
timeout: 5,
attempts: 2,
},
},
{
name: "testdata/empty-resolv.conf",
conf: dnsConfig{
ndots: 1,
timeout: 5,
attempts: 2,
},
},
}
func TestDNSReadConfig(t *testing.T) {
for _, tt := range dnsReadConfigTests {
conf, err := dnsReadConfig(tt.name)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(conf, &tt.conf) {
t.Errorf("got %v; want %v", conf, &tt.conf)
}
}
}
|