-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathcredentials_test.go
51 lines (41 loc) · 1.09 KB
/
credentials_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
package mailgun
import (
"context"
"fmt"
"os"
"strings"
"testing"
"github.com/facebookgo/ensure"
)
func TestGetCredentials(t *testing.T) {
if reason := SkipNetworkTest(); reason != "" {
t.Skip(reason)
}
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
ctx := context.Background()
it := mg.ListCredentials(nil)
var page []Credential
for it.Next(ctx, &page) {
t.Logf("Login\tCreated At\t\n")
for _, c := range page {
t.Logf("%s\t%s\t\n", c.Login, c.CreatedAt)
}
}
ensure.Nil(t, it.Err())
}
func TestCreateDeleteCredentials(t *testing.T) {
if reason := SkipNetworkTest(); reason != "" {
t.Skip(reason)
}
domain := os.Getenv("MG_DOMAIN")
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
randomPassword := randomString(16, "pw")
randomID := strings.ToLower(randomString(16, "usr"))
randomLogin := fmt.Sprintf("%s@%s", randomID, domain)
ctx := context.Background()
ensure.Nil(t, mg.CreateCredential(ctx, randomLogin, randomPassword))
ensure.Nil(t, mg.ChangeCredentialPassword(ctx, randomID, randomString(16, "pw2")))
ensure.Nil(t, mg.DeleteCredential(ctx, randomID))
}