-
Notifications
You must be signed in to change notification settings - Fork 0
/
records_test.go
134 lines (123 loc) · 3.19 KB
/
records_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
126
127
128
129
130
131
132
133
134
package gandiapi
import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestGetRecords(t *testing.T) {
responseData := []byte(`
[
{
"rrset_type": "A",
"rrset_ttl": 1800,
"rrset_name": "@",
"rrset_href": "https://api.gandi.net/v5/livedns/domains/example.com/records/40/A",
"rrset_values": [
"45.79.62.185"
]
},
{
"rrset_type": "MX",
"rrset_ttl": 10800,
"rrset_name": "@",
"rrset_href": "https://api.gandi.net/v5/livedns/domains/example.com/records/40/MX",
"rrset_values": [
"10 spool.mail.gandi.net.",
"50 fb.mail.gandi.net."
]
},
{
"rrset_type": "TXT",
"rrset_ttl": 10800,
"rrset_name": "@",
"rrset_href": "https://api.gandi.net/v5/livedns/domains/example.com/records/40/TXT",
"rrset_values": [
"\"v=spf1 include:_mailcust.gandi.net ?all\""
]
},
{
"rrset_type": "CNAME",
"rrset_ttl": 10800,
"rrset_name": "blog",
"rrset_href": "https://api.gandi.net/v5/livedns/domains/example.com/records/blog/CNAME",
"rrset_values": [
"blogs.vip.gandi.net."
]
},
{
"rrset_type": "A",
"rrset_ttl": 1800,
"rrset_name": "raneto",
"rrset_href": "https://api.gandi.net/v5/livedns/domains/example.com/records/raneto/A",
"rrset_values": [
"45.79.62.185"
]
},
{
"rrset_type": "CNAME",
"rrset_ttl": 10800,
"rrset_name": "webmail",
"rrset_href": "https://api.gandi.net/v5/livedns/domains/example.com/records/webmail/CNAME",
"rrset_values": [
"webmail.gandi.net."
]
},
{
"rrset_type": "CNAME",
"rrset_ttl": 10800,
"rrset_name": "www",
"rrset_href": "https://api.gandi.net/v5/livedns/domains/example.com/records/www/CNAME",
"rrset_values": [
"webredir.vip.gandi.net."
]
},
{
"rrset_type": "AAAA",
"rrset_ttl": 1800,
"rrset_name": "x23",
"rrset_href": "https://api.gandi.net/v5/livedns/domains/example.com/records/x23/AAAA",
"rrset_values": [
"2a02:8108:13b:bb00:211:32ff:fe15:d122"
]
}
]
`)
mockDomainName := "example.com"
client, mux, teardown := setup()
defer teardown()
mux.HandleFunc("/livedns/domains/"+mockDomainName+"/records", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string(responseData))
})
records, err := client.GetRecords(mockDomainName)
if err != nil {
t.Errorf("got error with GetZones %v", err)
}
var expected []Record
err = json.Unmarshal(responseData, &expected)
if err != nil {
t.Errorf("got error with Unmarshal %v %v", err, records)
}
if !reflect.DeepEqual(records, expected) {
t.Errorf("client.GetRecords() got %v expected %v\n", records, expected)
}
}
func TestCreateRecord(t *testing.T) {
mockDomainName := "example.com"
client, mux, teardown := setup()
defer teardown()
mux.HandleFunc("/livedns/domains/"+mockDomainName+"/records", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string([]byte(`{"message": "DNS Record Created"}`)))
})
data := Record{
RrsetType: "A",
RrsetTTL: 300,
RrsetName: "amazing-cli",
RrsetValues: []string{"18.185.88.103"},
}
_, err := client.CreateRecord(data, mockDomainName)
if err != nil {
t.Errorf("got error with CreateError %v", err)
}
}