-
Notifications
You must be signed in to change notification settings - Fork 2
/
set_test.go
85 lines (81 loc) · 1.23 KB
/
set_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
package newdns
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSetValidate(t *testing.T) {
table := []struct {
set Set
err string
}{
{
set: Set{
Name: "foo",
},
err: "invalid name: foo",
},
{
set: Set{
Name: "example.com.",
},
err: "unsupported type: 0",
},
{
set: Set{
Name: "example.com.",
Type: A,
},
err: "missing records",
},
{
set: Set{
Name: "example.com.",
Type: A,
Records: []Record{
{Address: "foo"},
},
},
err: "invalid record: invalid IPv4 address: foo",
},
{
set: Set{
Name: "example.com.",
Type: TXT,
Records: []Record{
{},
},
},
err: "invalid record: missing data",
},
{
set: Set{
Name: "example.com.",
Type: CNAME,
Records: []Record{
{},
{},
},
},
err: "multiple CNAME records",
},
{
set: Set{
Name: "example.com.",
Type: A,
Records: []Record{
{Address: "1.2.3.4"},
{Address: "1.2.3.4"},
},
},
err: "duplicate address: 1.2.3.4",
},
}
for i, item := range table {
err := item.set.Validate()
if err != nil {
assert.Equal(t, item.err, err.Error(), i)
} else {
assert.Equal(t, item.err, "", item)
}
}
}