forked from rverst/coredns-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_test.go
94 lines (78 loc) · 2.66 KB
/
redis_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package redis
import (
"github.com/clustor/coredns-redis/record"
"net"
"testing"
)
const (
prefix, suffix = "sls_", ""
minTtl = 300
testTtl = 4242
txt = "Lamas, seekers, and great monkeys will always protect them."
wcTxt = "This is a wildcard TXT record"
)
var zones = []string{"example.net", "example.org"}
type testRecord struct {
l string
r record.Record
}
var testRecords = []testRecord{
{"@", record.A{Ttl: testTtl, Ip: net.ParseIP("93.184.216.34")}},
{"www", record.A{Ttl: testTtl, Ip: net.ParseIP("93.184.216.34")}},
{"@", record.AAAA{Ttl: testTtl, Ip: net.ParseIP("2606:2800:220:1:248:1893:25c8:1946")}},
{"www", record.AAAA{Ttl: testTtl, Ip: net.ParseIP("2606:2800:220:1:248:1893:25c8:1946")}},
{"@", record.TXT{Ttl: testTtl, Text: txt}},
{"@", record.NS{Ttl: testTtl, Host: "ns1.example.org."}},
{"@", record.NS{Ttl: testTtl, Host: "ns2.example.org."}},
{"@", record.MX{Ttl: testTtl, Host: "mail.example.org.", Preference: 10}},
{"wwx", record.CNAME{Ttl: testTtl, Host: "www.example.org."}},
{"_autodiscover._tcp", record.SRV{Ttl: testTtl, Priority: 10, Weight: 50, Port: 443, Target: "mail.example.org."}},
{"ns1", record.A{Ttl: testTtl, Ip: net.ParseIP("93.184.216.36")}},
{"ns2", record.A{Ttl: testTtl, Ip: net.ParseIP("93.184.216.37")}},
{"mail", record.A{Ttl: testTtl, Ip: net.ParseIP("93.184.216.38")}},
{"mail", record.AAAA{Ttl: testTtl, Ip: net.ParseIP("2606:2800:220:1:248:1893:25c8:1947")}},
{"@", record.CAA{Ttl: testTtl, Flag: 0, Tag: "issue", Value: "letsencrypt.org"}},
{"lb", record.A{Ttl: testTtl, Ip: net.ParseIP("93.184.216.39")}},
{"lb", record.A{Ttl: testTtl, Ip: net.ParseIP("93.184.216.40")}},
{"lb", record.A{Ttl: testTtl, Ip: net.ParseIP("93.184.216.41")}},
{"lb", record.A{Ttl: testTtl, Ip: net.ParseIP("93.184.216.42")}},
{"*", record.A{Ttl: testTtl, Ip: net.ParseIP("93.184.216.43")}},
{"*", record.TXT{Ttl: testTtl, Text: wcTxt}},
}
func newRedis() (*Redis, error) {
r := New()
r.SetKeyPrefix(prefix)
r.SetKeySuffix(suffix)
r.SetDefaultTtl(minTtl)
r.SetAddress("192.168.0.100:6379")
if err := r.Connect(); err != nil {
return nil, err
}
return r, nil
}
func TestRedis_SaveZone(t *testing.T) {
redis, err := newRedis()
if err != nil {
t.Error(err)
}
for _, z := range zones {
zone := record.NewZone(z, record.SOA{
Ttl: testTtl,
MName: "ns1." + z + ".",
RName: "hostmaster." + z,
Serial: 2006010201,
Refresh: 3600,
Retry: 1800,
Expire: 10000,
MinTtl: 300,
})
for _, tr := range testRecords {
zone.Add(tr.l, tr.r)
}
t.Run(zone.Name, func(t *testing.T) {
if err := redis.SaveZone(*zone); err != nil {
t.Errorf("SaveZone() error = %v", err)
}
})
}
}