forked from mailgun/mailgun-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domains_test.go
64 lines (52 loc) · 1.59 KB
/
domains_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
package mailgun
import (
"net/http"
"testing"
"github.com/facebookgo/ensure"
)
func TestGetDomains(t *testing.T) {
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
n, domains, err := mg.GetDomains(DefaultLimit, DefaultSkip)
ensure.Nil(t, err)
t.Logf("TestGetDomains: %d domains retrieved\n", n)
for _, d := range domains {
t.Logf("TestGetDomains: %#v\n", d)
}
}
func TestGetSingleDomain(t *testing.T) {
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
_, domains, err := mg.GetDomains(DefaultLimit, DefaultSkip)
ensure.Nil(t, err)
dr, rxDnsRecords, txDnsRecords, err := mg.GetSingleDomain(domains[0].Name)
ensure.Nil(t, err)
t.Logf("TestGetSingleDomain: %#v\n", dr)
for _, rxd := range rxDnsRecords {
t.Logf("TestGetSingleDomains: %#v\n", rxd)
}
for _, txd := range txDnsRecords {
t.Logf("TestGetSingleDomains: %#v\n", txd)
}
}
func TestGetSingleDomainNotExist(t *testing.T) {
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
_, _, _, err = mg.GetSingleDomain(randomString(32, "com.edu.org.") + ".com")
if err == nil {
t.Fatal("Did not expect a domain to exist")
}
ure, ok := err.(*UnexpectedResponseError)
ensure.True(t, ok)
ensure.DeepEqual(t, ure.Actual, http.StatusNotFound)
}
func TestAddDeleteDomain(t *testing.T) {
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
// First, we need to add the domain.
randomDomainName := randomString(16, "DOMAIN") + ".example.com"
randomPassword := randomString(16, "PASSWD")
ensure.Nil(t, mg.CreateDomain(randomDomainName, randomPassword, Tag, false))
// Next, we delete it.
ensure.Nil(t, mg.DeleteDomain(randomDomainName))
}