forked from mailgun/mailgun-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ips_test.go
59 lines (44 loc) · 1.24 KB
/
ips_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
package mailgun_test
import (
"context"
"os"
"testing"
"github.com/facebookgo/ensure"
"github.com/mailgun/mailgun-go/v4"
)
var server mailgun.MockServer
// Setup and shutdown the mailgun mock server for the entire test suite
func TestMain(m *testing.M) {
server = mailgun.NewMockServer()
defer server.Stop()
os.Exit(m.Run())
}
func TestListIPS(t *testing.T) {
mg := mailgun.NewMailgun(testDomain, testKey)
mg.SetAPIBase(server.URL())
ctx := context.Background()
list, err := mg.ListIPS(ctx, false)
ensure.Nil(t, err)
ensure.DeepEqual(t, len(list), 2)
ip, err := mg.GetIP(ctx, list[0].IP)
ensure.Nil(t, err)
ensure.DeepEqual(t, ip.IP, list[0].IP)
ensure.DeepEqual(t, ip.Dedicated, true)
ensure.DeepEqual(t, ip.RDNS, "luna.mailgun.net")
}
func TestDomainIPS(t *testing.T) {
mg := mailgun.NewMailgun(testDomain, testKey)
mg.SetAPIBase(server.URL())
ctx := context.Background()
err := mg.AddDomainIP(ctx, "192.172.1.1")
ensure.Nil(t, err)
list, err := mg.ListDomainIPS(ctx)
ensure.Nil(t, err)
ensure.DeepEqual(t, len(list), 1)
ensure.DeepEqual(t, list[0].IP, "192.172.1.1")
err = mg.DeleteDomainIP(ctx, "192.172.1.1")
ensure.Nil(t, err)
list, err = mg.ListDomainIPS(ctx)
ensure.Nil(t, err)
ensure.DeepEqual(t, len(list), 0)
}