-
Notifications
You must be signed in to change notification settings - Fork 0
/
provisioner_test.go
125 lines (108 loc) · 2.75 KB
/
provisioner_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package dubber
import (
"bytes"
"regexp"
"testing"
)
type tpChange struct {
adds Zone
rems Zone
}
type testProvisioner struct {
t *testing.T
rz Zone
of map[string]*regexp.Regexp
}
func (tp *testProvisioner) UpdateZone(wanted, unwanted, desired, remote Zone) error {
tp.t.Logf("wanted:\n%s", wanted)
tp.t.Logf("unwanted:\n%s", unwanted)
tp.t.Logf("desired:\n%s", desired)
tp.t.Logf("remote:\n%s", remote)
return nil
}
func (tp *testProvisioner) GroupFlags() []string {
return []string{"setID", "country"}
}
func (tp *testProvisioner) OwnerFlags() (map[string]*regexp.Regexp, error) {
return tp.of, nil
}
func (tp *testProvisioner) RemoteZone() (Zone, error) {
return tp.rz, nil
}
func TestServerReconcile(t *testing.T) {
z, err := ParseZoneData(bytes.NewBuffer([]byte(`
; comment is ignored
thing.example.com. 10 IN A 11.11.11.11 ; comment=1 setID=2
thing.example.com. 10 IN A 12.12.12.12
`)))
if err != nil {
t.Fatalf("error parsing local zone, %v", err)
}
rz, err := ParseZoneData(bytes.NewBuffer([]byte(`thing.example.com. 10 IN A 8.8.8.8 ; comment=1
$TTL 86400
@ IN SOA example.com. root.example.com. (
100 ;Serial
3600 ;Refresh
1800 ;Retry
6048 ;Expire
8640 ;Minimum TTL
)
thing.example.com. 10 IN A 6.6.6.6
thing2.example.com. 10 IN A 5.5.5.5
thing.example.com. 10 IN A 7.7.7.7 ; setID=1 comment=1
thing.example.com. 10 IN A 8.8.8.8 ; setID=1 comment=2
thing.example.com. 10 IN A 10.10.10.10`)))
if err != nil {
t.Fatalf("error parsing remote zone, %v", err)
}
tp := &testProvisioner{
t: t,
rz: rz,
}
var srv *Server
err = srv.ReconcileZone(tp, z)
if err != nil {
t.Fatalf("error reconciling zone, %v", err)
}
}
func TestServerReconcile_OwnerGroup(t *testing.T) {
z, err := ParseZoneData(bytes.NewBuffer([]byte(`
; comment is ignored
thing.example.com. 10 IN A 11.11.11.11 ; comment=1 setID=2
thing.example.com. 10 IN A 12.12.12.12
`)))
if err != nil {
t.Fatalf("error parsing local zone, %v", err)
}
rz, err := ParseZoneData(bytes.NewBuffer([]byte(`
$TTL 86400
@ IN SOA example.com. root.example.com. (
100 ;Serial
3600 ;Refresh
1800 ;Retry
6048 ;Expire
8640 ;Minimum TTL
)
thing.example.com. 10 IN A 6.6.6.6
thing2.example.com. 10 IN A 5.5.5.5
thing.example.com. 10 IN A 7.7.7.7 ; setID=1 comment=1
thing.example.com. 10 IN A 10.10.10.10
thing4.example.com. 10 IN A 9.9.9.9; setID=1
thing5.example.com. 10 IN A 9.9.9.9; setID=2
thing6.example.com. 10 IN A 11.11.11.11`)))
if err != nil {
t.Fatalf("error parsing remote zone, %v", err)
}
tp := &testProvisioner{
t: t,
rz: rz,
of: map[string]*regexp.Regexp{
"setID": regexp.MustCompile("^1$"),
},
}
var srv *Server
err = srv.ReconcileZone(tp, z)
if err != nil {
t.Fatalf("error reconciling zone, %v", err)
}
}