forked from mailgun/mailgun-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailgun_test.go
35 lines (27 loc) · 852 Bytes
/
mailgun_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
package mailgun_test
import (
"context"
"net/http"
"testing"
"github.com/facebookgo/ensure"
"github.com/mailgun/mailgun-go/v4"
)
const domain = "valid-mailgun-domain"
const apiKey = "valid-mailgun-api-key"
func TestMailgun(t *testing.T) {
m := mailgun.NewMailgun(domain, apiKey)
ensure.DeepEqual(t, m.Domain(), domain)
ensure.DeepEqual(t, m.APIKey(), apiKey)
ensure.DeepEqual(t, m.Client(), http.DefaultClient)
client := new(http.Client)
m.SetClient(client)
ensure.DeepEqual(t, client, m.Client())
}
func TestInvalidBaseAPI(t *testing.T) {
mg := mailgun.NewMailgun(testDomain, testKey)
mg.SetAPIBase("https://localhost")
ctx := context.Background()
_, err := mg.GetDomain(ctx, "unknown.domain")
ensure.NotNil(t, err)
ensure.DeepEqual(t, err.Error(), `BaseAPI must end with a /v2, /v3 or /v4; setBaseAPI("https://host/v3")`)
}