forked from mailgun/mailgun-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unsubscribes_test.go
89 lines (70 loc) · 2.06 KB
/
unsubscribes_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
package mailgun
import (
"context"
"os"
"testing"
"github.com/facebookgo/ensure"
)
func TestCreateUnsubscriber(t *testing.T) {
if reason := SkipNetworkTest(); reason != "" {
t.Skip(reason)
}
email := randomEmail("unsubcribe", os.Getenv("MG_DOMAIN"))
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
ctx := context.Background()
// Create unsubscription record
ensure.Nil(t, mg.CreateUnsubscribe(ctx, email, "*"))
}
func TestListUnsubscribes(t *testing.T) {
if reason := SkipNetworkTest(); reason != "" {
t.Skip(reason)
}
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
ctx := context.Background()
it := mg.ListUnsubscribes(nil)
var page []Unsubscribe
for it.Next(ctx, &page) {
t.Logf("Received %d unsubscribe records.\n", len(page))
if len(page) > 0 {
t.Log("ID\tAddress\tCreated At\tTags\t")
for _, u := range page {
t.Logf("%s\t%s\t%s\t%s\t\n", u.ID, u.Address, u.CreatedAt, u.Tags)
}
}
}
ensure.Nil(t, it.Err())
}
func TestGetUnsubscribe(t *testing.T) {
if reason := SkipNetworkTest(); reason != "" {
t.Skip(reason)
}
email := randomEmail("unsubcribe", os.Getenv("MG_DOMAIN"))
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
ctx := context.Background()
// Create unsubscription record
ensure.Nil(t, mg.CreateUnsubscribe(ctx, email, "*"))
u, err := mg.GetUnsubscribe(ctx, email)
ensure.Nil(t, err)
t.Logf("%s\t%s\t%s\t%s\t\n", u.ID, u.Address, u.CreatedAt, u.Tags)
// Destroy the unsubscription record
ensure.Nil(t, mg.DeleteUnsubscribe(ctx, email))
}
func TestCreateDestroyUnsubscription(t *testing.T) {
if reason := SkipNetworkTest(); reason != "" {
t.Skip(reason)
}
email := randomEmail("unsubcribe", os.Getenv("MG_DOMAIN"))
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
ctx := context.Background()
// Create unsubscription record
ensure.Nil(t, mg.CreateUnsubscribe(ctx, email, "*"))
_, err = mg.GetUnsubscribe(ctx, email)
ensure.Nil(t, err)
/*t.Logf("Received %d out of %d unsubscribe records.\n", len(us), n)*/
// Destroy the unsubscription record
ensure.Nil(t, mg.DeleteUnsubscribe(ctx, email))
}