-
Notifications
You must be signed in to change notification settings - Fork 2
/
message_test.go
70 lines (56 loc) · 1.23 KB
/
message_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
package nameserver
import (
"strings"
. "gopkg.in/check.v1"
)
type MessageSuite struct{}
var _ = Suite(&MessageSuite{})
func domainNameToLabels(domain string) []label {
labels := []label{}
for _, p := range strings.Split(domain, ".") {
labels = append(labels, label(p))
}
return labels
}
func createQueryFor(d string, id uint16) *message {
return &message{
header: &header{
id: id,
qdCount: oneQuery,
},
query: &query{
qname: domainNameToLabels(d),
qtype: qtypeA,
qclass: qclassIN,
},
}
}
func (s *MessageSuite) Test_ResponseForAuthoritativeZoneQuery(c *C) {
q := createQueryFor("twtiger.com.", 1234)
r := q.response()
c.Assert(r.header, DeepEquals,
&header{
id: 1234,
qdCount: oneQuery,
anCount: twoAnswers,
})
c.Assert(r.query, DeepEquals, q.query)
c.Assert(len(r.answers), Equals, 2)
c.Assert(r.answers, DeepEquals,
[]*record{
tigerRecord1,
tigerRecord2,
})
}
func (s *MessageSuite) Test_ResponseForExtNameServerQuery(c *C) {
q := createQueryFor("wireshark.org.", 456)
r := q.response()
c.Assert(r.header, DeepEquals,
&header{
id: 456,
qdCount: oneQuery,
anCount: 0,
})
c.Assert(r.query, DeepEquals, q.query)
c.Assert(len(r.answers), Equals, 0)
}