-
Notifications
You must be signed in to change notification settings - Fork 143
/
ips_test.go
60 lines (45 loc) · 1.26 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
60
package mailgun_test
import (
"context"
"os"
"testing"
"github.com/mailgun/mailgun-go/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
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)
require.NoError(t, err)
require.Len(t, list, 2)
ip, err := mg.GetIP(ctx, list[0].IP)
require.NoError(t, err)
assert.Equal(t, list[0].IP, ip.IP)
assert.True(t, ip.Dedicated)
assert.Equal(t, "luna.mailgun.net", ip.RDNS)
}
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")
require.NoError(t, err)
list, err := mg.ListDomainIPS(ctx)
require.NoError(t, err)
require.Len(t, list, 1)
require.Equal(t, "192.172.1.1", list[0].IP)
err = mg.DeleteDomainIP(ctx, "192.172.1.1")
require.NoError(t, err)
list, err = mg.ListDomainIPS(ctx)
require.NoError(t, err)
require.Len(t, list, 0)
}