forked from mailgun/mailgun-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
credentials_test.go
43 lines (34 loc) · 1.02 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
package mailgun_test
import (
"context"
"fmt"
"strings"
"testing"
"github.com/mailgun/mailgun-go/v4"
"github.com/facebookgo/ensure"
)
func TestGetCredentials(t *testing.T) {
mg := mailgun.NewMailgun(testDomain, testKey)
mg.SetAPIBase(server.URL())
ctx := context.Background()
it := mg.ListCredentials(nil)
var page []mailgun.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) {
mg := mailgun.NewMailgun(testDomain, testKey)
mg.SetAPIBase(server.URL())
randomPassword := randomString(16, "pw")
randomID := strings.ToLower(randomString(16, "usr"))
randomLogin := fmt.Sprintf("%s@%s", randomID, testDomain)
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))
}