forked from keighl/postmark
-
Notifications
You must be signed in to change notification settings - Fork 1
/
servers_test.go
83 lines (72 loc) · 2.01 KB
/
servers_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
package postmark
import (
"net/http"
"testing"
"goji.io/pat"
)
func TestGetServer(t *testing.T) {
responseJSON := `{
"ID": 1,
"Name": "Staging Testing",
"ApiTokens": [
"server token"
],
"ServerLink": "https://postmarkapp.com/servers/1/overview",
"Color": "red",
"SmtpApiActivated": true,
"RawEmailEnabled": false,
"InboundAddress": "[email protected]",
"InboundHookUrl": "http://hooks.example.com/inbound",
"BounceHookUrl": "http://hooks.example.com/bounce",
"OpenHookUrl": "http://hooks.example.com/open",
"PostFirstOpenOnly": false,
"TrackOpens": false,
"InboundDomain": "",
"InboundHash": "yourhash",
"InboundSpamThreshold": 0
}`
tMux.HandleFunc(pat.Get("/servers/:serverID"), func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(responseJSON))
})
res, err := client.GetServer("1")
if err != nil {
t.Fatalf("GetServer: %s", err.Error())
}
if res.Name != "Staging Testing" {
t.Fatalf("GetServer: wrong name!: %s", res.Name)
}
}
func TestEditServer(t *testing.T) {
responseJSON := `{
"ID": 1,
"Name": "Production Testing",
"ApiTokens": [
"Server Token"
],
"ServerLink": "https://postmarkapp.com/servers/1/overview",
"Color": "blue",
"SmtpApiActivated": false,
"RawEmailEnabled": false,
"InboundAddress": "[email protected]",
"InboundHookUrl": "http://hooks.example.com/inbound",
"BounceHookUrl": "http://hooks.example.com/bounce",
"OpenHookUrl": "http://hooks.example.com/open",
"PostFirstOpenOnly": false,
"TrackOpens": false,
"InboundDomain": "",
"InboundHash": "yourhash",
"InboundSpamThreshold": 10
}`
tMux.HandleFunc(pat.Put("/servers/:serverID"), func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(responseJSON))
})
res, err := client.EditServer("1234", Server{
Name: "Production Testing",
})
if err != nil {
t.Fatalf("EditServer: %s", err.Error())
}
if res.Name != "Production Testing" {
t.Fatalf("EditServer: wrong name!: %s", res.Name)
}
}