forked from keighl/postmark
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdomains_test.go
159 lines (137 loc) · 4.4 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
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
package postmark
import (
"context"
"net/http"
"testing"
"goji.io/pat"
)
func TestGetDomain(t *testing.T) {
responseJSON := `{
"Name": "postmarkapp.com",
"SPFVerified": true,
"SPFHost": "postmarkapp.com",
"SPFTextValue": "v=spf1 a mx include:spf.mtasv.net ~all",
"DKIMVerified": false,
"WeakDKIM": false,
"DKIMHost": "jan2013pm._domainkey.postmarkapp.com",
"DKIMTextValue": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJ...",
"DKIMPendingHost": "20131031155228pm._domainkey.postmarkapp.com",
"DKIMPendingTextValue": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFn...",
"DKIMRevokedHost": "",
"DKIMRevokedTextValue": "",
"SafeToRemoveRevokedKeyFromDNS": false,
"DKIMUpdateStatus": "Pending",
"ReturnPathDomain": "pm-bounces.postmarkapp.com",
"ReturnPathDomainVerified": false,
"ReturnPathDomainCNAMEValue": "pm.mtasv.net",
"ID": 1234
}`
tMux.HandleFunc(pat.Get("/domains/:domainID"), func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(responseJSON))
})
res, err := client.GetDomain(context.Background(), 1234)
if err != nil {
t.Fatalf("GetDomain: %s", err.Error())
}
if res.Name != "postmarkapp.com" {
t.Fatalf("GetDomain: wrong name!: %s", res.Name)
}
}
func TestCreateDomain(t *testing.T) {
responseJSON := `{
"Name": "example.com",
"SPFVerified": false,
"SPFHost": "example.com",
"SPFTextValue": "v=spf1 a mx include:spf.mtasv.net ~all",
"DKIMVerified": false,
"WeakDKIM": false,
"DKIMHost": "",
"DKIMTextValue": "",
"DKIMPendingHost": "20131031155228pm._domainkey.example.com",
"DKIMPendingTextValue": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFn...",
"DKIMRevokedHost": "",
"DKIMRevokedTextValue": "",
"SafeToRemoveRevokedKeyFromDNS": false,
"DKIMUpdateStatus": "Pending",
"ReturnPathDomain": "pm-bounces.example.com",
"ReturnPathDomainVerified": false,
"ReturnPathDomainCNAMEValue": "pm.mtasv.net",
"ID": 1234
}`
tMux.HandleFunc(pat.Post("/domains"), func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(responseJSON))
})
res, err := client.CreateDomain(context.Background(), DomainCreateRequest{
Name: "example.com",
ReturnPathDomain: "pm-bounces.example.com",
})
if err != nil {
t.Fatalf("CreateDomain: %s", err.Error())
}
if res.Name != "example.com" {
t.Fatalf("CreateDomain: wrong name!: %s", res.Name)
}
if res.ReturnPathDomain != "pm-bounces.example.com" {
t.Fatalf("CreateDomain: wrong ReturnPathDomain!: %s", res.ReturnPathDomain)
}
}
func TestEditDomain(t *testing.T) {
responseJSON := `{
"Name": "example.com",
"SPFVerified": false,
"SPFHost": "example.com",
"SPFTextValue": "v=spf1 a mx include:spf.mtasv.net ~all",
"DKIMVerified": false,
"WeakDKIM": false,
"DKIMHost": "20160921046319pm._domainkey.example.com",
"DKIMTextValue": "k=rsa; p=MIGfMA0GDRrFQJc5dZEBAQUAA4GNADCBiQKBgQCFn...",
"DKIMPendingHost": "20131031155228pm._domainkey.example.com",
"DKIMPendingTextValue": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFn...",
"DKIMRevokedHost": "",
"DKIMRevokedTextValue": "",
"SafeToRemoveRevokedKeyFromDNS": false,
"DKIMUpdateStatus": "Pending",
"ReturnPathDomain": "pm-bounces.example.com",
"ReturnPathDomainVerified": false,
"ReturnPathDomainCNAMEValue": "pm.mtasv.net",
"ID": 1234
}`
tMux.HandleFunc(pat.Put("/domains/:domainID"), func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(responseJSON))
})
res, err := client.EditDomain(context.Background(), 1234, DomainEditRequest{
ReturnPathDomain: "pm-bounces.example.com",
})
if err != nil {
t.Fatalf("EditDomain: %s", err.Error())
}
if res.Name != "example.com" {
t.Fatalf("EditDomain: wrong name!: %s", res.Name)
}
if res.ReturnPathDomain != "pm-bounces.example.com" {
t.Fatalf("EditDomain: wrong ReturnPathDomain!: %s", res.ReturnPathDomain)
}
}
func TestDeleteDomain(t *testing.T) {
responseJSON := `{
"ErrorCode": 0,
"Message": "Domain example.com removed."
}`
tMux.HandleFunc(pat.Delete("/domains/:domainID"), func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(responseJSON))
})
// Success
err := client.DeleteDomain(context.Background(), 1234)
if err != nil {
t.Fatalf("DeleteDomain: %s", err.Error())
}
// Failure
responseJSON = `{
"ErrorCode": 402,
"Message": "Invalid JSON"
}`
err = client.DeleteDomain(context.Background(), 1234)
if err == nil {
t.Fatalf("DeleteDomain: should have failed")
}
}