-
Notifications
You must be signed in to change notification settings - Fork 1
/
dnsserver_test.go
71 lines (64 loc) · 1.75 KB
/
dnsserver_test.go
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
70
71
package netem
import (
"net"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestDNSConfig(t *testing.T) {
t.Run("removing a nonexisting record does not cause any issue", func(t *testing.T) {
dc := NewDNSConfig()
dc.RemoveRecord("www.example.com")
})
t.Run("we can remove a previously added record", func(t *testing.T) {
dc := NewDNSConfig()
t.Run("the record should be there once we have added it", func(t *testing.T) {
if err := dc.AddRecord("www.example.com", "www1.example.com", "1.2.3.4", "4.5.6.7"); err != nil {
t.Fatal(err)
}
rec, good := dc.Lookup("www.example.com")
if !good {
t.Fatal("the record is not there")
}
expect := &DNSRecord{
A: []net.IP{
net.IPv4(1, 2, 3, 4),
net.IPv4(4, 5, 6, 7),
},
CNAME: "www1.example.com.",
}
if diff := cmp.Diff(expect, rec); diff != "" {
t.Fatal(diff)
}
t.Run("the record should disappear once we have removed it", func(t *testing.T) {
dc.RemoveRecord("www.example.com")
rec, good := dc.Lookup("www.example.com")
if good {
t.Fatal("expected the record to be nonexistent")
}
if rec != nil {
t.Fatal("expected a nil record")
}
})
})
})
t.Run("we can clone a DNSConfig", func(t *testing.T) {
config := NewDNSConfig()
config.AddRecord("www.example.com", "", "130.192.91.211")
other := config.Clone()
config.RemoveRecord("www.example.com")
if _, good := config.Lookup("www.example.com"); good {
t.Fatal("expected record to be missing")
}
record, good := other.Lookup("www.example.com")
if !good {
t.Fatal("expected to see record")
}
expect := &DNSRecord{
A: []net.IP{net.IPv4(130, 192, 91, 211)},
CNAME: "",
}
if diff := cmp.Diff(expect, record); diff != "" {
t.Fatal(diff)
}
})
}