forked from mailgun/mailgun-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhooks_test.go
41 lines (30 loc) · 888 Bytes
/
webhooks_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
package mailgun
import (
"testing"
"github.com/facebookgo/ensure"
)
func TestWebhookCRUD(t *testing.T) {
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
var countHooks = func() int {
hooks, err := mg.GetWebhooks()
ensure.Nil(t, err)
return len(hooks)
}
hookCount := countHooks()
ensure.Nil(t, mg.CreateWebhook("deliver", "http://www.example.com"))
defer func() {
ensure.Nil(t, mg.DeleteWebhook("deliver"))
newCount := countHooks()
ensure.DeepEqual(t, newCount, hookCount)
}()
newCount := countHooks()
ensure.False(t, newCount <= hookCount)
theURL, err := mg.GetWebhookByType("deliver")
ensure.Nil(t, err)
ensure.DeepEqual(t, theURL, "http://www.example.com")
ensure.Nil(t, mg.UpdateWebhook("deliver", "http://api.example.com"))
hooks, err := mg.GetWebhooks()
ensure.Nil(t, err)
ensure.DeepEqual(t, hooks["deliver"], "http://api.example.com")
}