-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain_test.go
119 lines (99 loc) · 2.43 KB
/
domain_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
package dogo
import (
"encoding/json"
"fmt"
"net/http"
"testing"
)
func Test_ListDomains(t *testing.T) {
setup(t)
defer teardown()
want := &Domain{
Name: "example.com",
TTL: 1800,
ZoneFile: "Example zone file text...",
}
mux.HandleFunc("/domains", func(w http.ResponseWriter, r *http.Request) {
assertEqual(t, r.Method, "GET")
fmt.Fprint(w, listDomainsExample)
})
domains, err := client.ListDomains()
assertEqual(t, err, nil)
assertEqual(t, len(domains), 1)
assertEqual(t, domains[0].Name, want.Name)
assertEqual(t, domains[0].TTL, want.TTL)
assertEqual(t, domains[0].ZoneFile, want.ZoneFile)
}
func Test_GetDomain(t *testing.T) {
setup(t)
defer teardown()
want := &Domain{
Name: "example.com",
TTL: 1800,
ZoneFile: "Example zone file text...",
}
mux.HandleFunc("/domains/example.com", func(w http.ResponseWriter, r *http.Request) {
assertEqual(t, r.Method, "GET")
fmt.Fprint(w, domainExample)
})
domain, err := client.GetDomain(want.Name)
assertEqual(t, err, nil)
assertEqual(t, domain.Name, want.Name)
assertEqual(t, domain.TTL, want.TTL)
assertEqual(t, domain.ZoneFile, want.ZoneFile)
}
func Test_CreateDomain(t *testing.T) {
setup(t)
defer teardown()
want := &Domain{
Name: "example.com",
TTL: 1800,
ZoneFile: "Example zone file text...",
}
opts := &CreateDomainOpts{
Name: "example.com",
IPAddress: "127.0.0.20",
}
mux.HandleFunc("/domains", func(w http.ResponseWriter, r *http.Request) {
v := new(CreateDomainOpts)
json.NewDecoder(r.Body).Decode(v)
assertEqual(t, r.Method, "POST")
assertEqual(t, v, opts)
fmt.Fprint(w, domainExample)
})
domain, err := client.CreateDomain(opts)
assertEqual(t, err, nil)
assertEqual(t, domain.Name, want.Name)
assertEqual(t, domain.TTL, want.TTL)
assertEqual(t, domain.ZoneFile, want.ZoneFile)
}
func Test_DeleteDomain(t *testing.T) {
setup(t)
defer teardown()
name := "example.com"
mux.HandleFunc("/domains/example.com", func(w http.ResponseWriter, r *http.Request) {
assertEqual(t, r.Method, "DELETE")
fmt.Fprint(w, "")
})
err := client.DeleteDomain(name)
assertEqual(t, err, nil)
}
var listDomainsExample = `{
"domains": [
{
"name": "example.com",
"ttl": 1800,
"zone_file": "Example zone file text..."
}
],
"meta": {
"total": 1
}
}`
var domainExample = `{
"domain": {
"name": "example.com",
"ttl": 1800,
"zone_file": "Example zone file text..."
}
}`