-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel_test.go
More file actions
194 lines (187 loc) · 3.94 KB
/
model_test.go
File metadata and controls
194 lines (187 loc) · 3.94 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package hosttech
import (
"github.com/libdns/libdns"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestHosttechZoneToLibdnsZone(t *testing.T) {
input := map[string]struct {
expectedResult libdns.Zone
data HosttechZone
}{
"Example": {
expectedResult: libdns.Zone{Name: "example.com"},
data: HosttechZone{
Id: 1,
Name: "example.com",
Email: "admin@example.com",
TTL: 60000,
Nameserver: "ns1.example.com",
DNSSEC: false,
DNSSECEmail: "dnssec@example.com",
},
},
}
for name, testStruct := range input {
t.Run(name, func(t *testing.T) {
output := testStruct.data.toLibdnsZone()
assert.Equal(t, testStruct.expectedResult, output)
})
}
}
func TestHosttechRecordToLibdnsRecord(t *testing.T) {
zone := "example.com"
input := map[string]struct {
expectedResult libdns.Record
data HosttechRecord
}{
"ARecord Test": {
expectedResult: libdns.Record{
ID: "14",
Type: "A",
Name: "sub",
Value: "192.168.68.1",
TTL: 1800 * time.Second,
Priority: 0,
},
data: ARecord{
Base: Base{
Id: 14,
Type: "A",
TTL: 1800,
Comment: "Some comment",
},
Name: "sub.example.com",
IPV4: "192.168.68.1",
},
},
"AAAARecord Test": {
expectedResult: libdns.Record{
ID: "23",
Type: "AAAA",
Name: "sub",
Value: "2607:f0d0:1002:51::4",
TTL: 1800 * time.Second,
Priority: 0,
},
data: AAAARecord{
Base: Base{
Id: 23,
Type: "AAAA",
TTL: 1800,
Comment: "Some comment",
},
Name: "sub.example.com",
IPV6: "2607:f0d0:1002:51::4",
},
},
"NSRecord Test": {
expectedResult: libdns.Record{
ID: "12",
Type: "NS",
Name: "sub",
Value: "ns1.example.com",
TTL: 1900 * time.Second,
Priority: 0,
},
data: NSRecord{
Base: Base{
Id: 12,
Type: "NS",
TTL: 1900,
Comment: "Some comment",
},
OwnerName: "sub.example.com",
TargetName: "ns1.example.com",
},
},
"CNAMERecord Test": {
expectedResult: libdns.Record{
ID: "143",
Type: "CNAME",
Name: "sub",
Value: "site.example.com",
TTL: 1700 * time.Second,
Priority: 0,
},
data: CNAMERecord{
Base: Base{
Id: 143,
Type: "CNAME",
TTL: 1700,
Comment: "Some comment",
},
Name: "sub.example.com",
Cname: "site.example.com",
},
},
"MXRecord Test": {
expectedResult: libdns.Record{
ID: "748",
Type: "MX",
Name: "sub",
Value: "mail.server.com",
TTL: 1750 * time.Second,
Priority: 10,
},
data: MXRecord{
Base: Base{
Id: 748,
Type: "MX",
TTL: 1750,
Comment: "Some comment",
},
Name: "mail.server.com",
OwnerName: "sub.example.com",
Pref: 10,
},
},
"TXTRecord Test": {
expectedResult: libdns.Record{
ID: "178",
Type: "TXT",
Name: "sub",
Value: "Some cool text",
TTL: 1690 * time.Second,
Priority: 0,
},
data: TXTRecord{
Base: Base{
Id: 178,
Type: "TXT",
TTL: 1690,
Comment: "Some comment",
},
Name: "sub.example.com",
Text: "Some cool text",
},
},
"TLSARecord Test": {
expectedResult: libdns.Record{
ID: "61",
Type: "TLSA",
Name: "sub",
Value: "TLSA text",
TTL: 1700 * time.Second,
Priority: 0,
},
data: TLSARecord{
Base: Base{
Id: 61,
Type: "TLSA",
TTL: 1700,
Comment: "Some comment",
},
Name: "sub.example.com",
Text: "TLSA text",
},
},
}
for name, testStruct := range input {
t.Run(name, func(t *testing.T) {
output := testStruct.data.toLibdnsRecord(zone)
assert.Equal(t, testStruct.expectedResult, output)
})
}
}