-
Notifications
You must be signed in to change notification settings - Fork 0
/
policy_test.go
71 lines (65 loc) · 1.51 KB
/
policy_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 dnsresolver
import (
"testing"
"time"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
)
func TestDefaultCachePolicy(t *testing.T) {
cases := []struct {
q dns.Question
answer []dns.RR
authority []dns.RR
want time.Duration
}{
{
q: dns.Question{Qtype: dns.TypeA, Name: "bbc.co.uk."},
authority: []dns.RR{
NS(t, "uk.", 172800, "nsa.nic.uk."),
},
want: 172800 * time.Second,
},
{
q: dns.Question{Qtype: dns.TypeA, Name: "bbc.co.uk."},
authority: []dns.RR{
NS(t, "bbc.co.uk.", 172800, "dns1.bbc.co.uk."),
},
want: 0,
},
{
q: dns.Question{Qtype: dns.TypeA, Name: "bbc.co.uk."},
authority: []dns.RR{
NS(t, "uk.", 172800, "nsa.nic.uk."),
NS(t, "uk.", 172800, "nsb.nic.uk."),
},
want: 172800 * time.Second,
},
{
q: dns.Question{Qtype: dns.TypeA, Name: "bbc.co.uk."},
authority: []dns.RR{
NS(t, "uk.", 172800, "nsa.nic.uk."),
NS(t, "co.uk.", 172800, "nsa.nic.uk."),
},
want: 0,
},
{
q: dns.Question{Qtype: dns.TypeA, Name: "bbc.co.uk."},
authority: []dns.RR{
NS(t, "uk.", 172800, "nsa.nic.uk."),
NS(t, "bbc.co.uk.", 172800, "dns1.bbc.co.uk."),
},
want: 0,
},
}
t.Parallel()
for _, tc := range cases {
t.Run("", func(t *testing.T) {
msg := dns.Msg{}
msg.Question = append(msg.Question, tc.q)
msg.Answer = append(msg.Answer, tc.answer...)
msg.Ns = append(msg.Ns, tc.authority...)
got := defaultCachePolicy(RecordSet{Raw: msg})
assert.Equal(t, tc.want, got)
})
}
}