-
Notifications
You must be signed in to change notification settings - Fork 0
/
domains_test.go
119 lines (106 loc) · 2.68 KB
/
domains_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 gandiapi
import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestGetDomains(t *testing.T) {
responseData := []byte(`
[
{
"status": [
"clientTransferProhibited"
],
"dates": {
"created_at": "2019-02-13T11:04:18Z",
"registry_created_at": "2019-02-13T10:04:18Z",
"registry_ends_at": "2021-02-13T10:04:18Z",
"updated_at": "2019-02-25T16:20:49Z"
},
"tags": [],
"fqdn": "example.net",
"id": "ba1167be-2f76-11e9-9dfb-00163ec4cb00",
"autorenew": false,
"tld": "net",
"owner": "alice_doe",
"orga_owner": "alice_doe",
"domain_owner": "Alice Doe",
"nameserver": {
"current": "livedns"
},
"href": "https://api.test/v5/domain/domains/example.net",
"fqdn_unicode": "example.net"
},
{
"status": [],
"dates": {
"created_at": "2019-01-15T14:19:59Z",
"registry_created_at": "2019-01-15T13:19:58Z",
"registry_ends_at": "2020-01-15T13:19:58Z",
"updated_at": "2019-01-15T13:30:42Z"
},
"tags": [],
"fqdn": "example.com",
"id": "42927d64-18c8-11e9-b9b5-00163ec4cb00",
"autorenew": false,
"tld": "fr",
"owner": "alice_doe",
"orga_owner": "alice_doe",
"domain_owner": "Alice Doe",
"nameserver": {
"current": "livedns"
},
"href": "https://api.test/v5/domain/domains/example.com",
"fqdn_unicode": "example.com"
}
]
`)
client, mux, teardown := setup()
defer teardown()
mux.HandleFunc("/domain/domains", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string(responseData))
})
domains, err := client.GetDomains()
if err != nil {
t.Errorf("got error with GetDomains %v", err)
}
var expected []DomainResponse
err = json.Unmarshal(responseData, &expected)
if err != nil {
t.Errorf("got error with Unmarshal %v %v", err, domains)
}
if !reflect.DeepEqual(domains, expected) {
t.Errorf("client.GetDomains got %v expected %v\n", domains, expected)
}
}
func TestCreateDomain(t *testing.T) {
mockDomainName := "example.com"
client, mux, teardown := setup()
defer teardown()
mux.HandleFunc("/domain/domains/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string([]byte(`{"status": "success"}`)))
})
contact := DomainContact{
City: "Paris",
Given: "Alice",
Family: "Doe",
Zip: "75001",
Country: "FR",
Streetaddr: "5 rue neuve",
Phone: "+33.123456789",
State: "FR-J",
Type: "individual",
Email: "alice@example.org",
}
data := DomainCreateRequest{
Fqdn: mockDomainName,
Owner: contact,
Duration: 5,
}
err := client.CreateDomain(data)
if err != nil {
t.Errorf("got error with CreateError %v", err)
}
}