-
Notifications
You must be signed in to change notification settings - Fork 0
/
domains_test.go
63 lines (47 loc) · 1.66 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
package postmark
import (
"fmt"
"os"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCRUDDomain(t *testing.T) {
if os.Getenv("INTEGRATION") != "true" {
t.Skip()
}
accountToken := os.Getenv("PM_ACCOUNT_TOKEN")
require.NotEmpty(t, accountToken, "PM_ACCOUNT_TOKEN not set for integration test")
c := NewClient(accountToken, "")
timestamp := time.Now().Unix()
testDomain := fmt.Sprintf("lib-test-name-%d.com", timestamp)
// Create
newDomain := Domain{
Name: testDomain,
ReturnPathDomain: fmt.Sprintf("bounces.%s", testDomain),
}
retDomain, err := c.CreateDomain(newDomain)
require.NoError(t, err, "errored creating domain")
require.NotEmpty(t, retDomain, "got empty domain returned")
require.NotEmpty(t, retDomain.ID, "missing domain ID")
// Read
readDomain, err := c.GetDomain(strconv.Itoa(retDomain.ID))
require.NoError(t, err, "error reading domain")
require.NotEmpty(t, readDomain, "got empty domain response on read")
assert.Equal(t, newDomain.Name, readDomain.Name, "name wrong")
assert.Equal(t, newDomain.ReturnPathDomain, readDomain.ReturnPathDomain, "return path wrong")
// Update
updatedDomain := Domain{
ReturnPathDomain: fmt.Sprintf("bounces-2.%s", testDomain),
}
err = c.UpdateDomain(strconv.Itoa(readDomain.ID), updatedDomain)
require.NoError(t, err, "error updating domain")
// Read
readDomain, err = c.GetDomain(strconv.Itoa(readDomain.ID))
assert.Equal(t, updatedDomain.ReturnPathDomain, readDomain.ReturnPathDomain, "return path not updated")
// Delete
err = c.DeleteDomain(strconv.Itoa(retDomain.ID))
require.NoError(t, err, "delete failed")
}