-
Notifications
You must be signed in to change notification settings - Fork 3
/
account_user_test.go
66 lines (56 loc) · 1.7 KB
/
account_user_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
65
66
package scalr
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAccountUsersList(t *testing.T) {
client := testClient(t)
ctx := context.Background()
t.Run("with empty options", func(t *testing.T) {
_, err := client.AccountUsers.List(ctx, AccountUserListOptions{})
require.Error(t, err)
assert.EqualError(t, err, "either filter[account] or filter[user] is required")
})
t.Run("with account option", func(t *testing.T) {
aul, err := client.AccountUsers.List(ctx, AccountUserListOptions{
Account: String(defaultAccountID),
})
require.NoError(t, err)
uIDs := make([]string, len(aul.Items))
for _, au := range aul.Items {
uIDs = append(uIDs, au.User.ID)
}
assert.Equal(t, 1, aul.CurrentPage)
assert.True(t, aul.TotalCount >= 1)
assert.Contains(t, uIDs, defaultUserID)
})
t.Run("with user option", func(t *testing.T) {
aul, err := client.AccountUsers.List(ctx, AccountUserListOptions{
User: String(defaultUserID),
})
require.NoError(t, err)
aIDs := make([]string, len(aul.Items))
for _, au := range aul.Items {
aIDs = append(aIDs, au.Account.ID)
}
assert.Equal(t, 1, aul.CurrentPage)
assert.True(t, aul.TotalCount >= 1)
assert.Contains(t, aIDs, defaultAccountID)
})
t.Run("without a valid account", func(t *testing.T) {
aul, err := client.AccountUsers.List(ctx, AccountUserListOptions{
Account: String(badIdentifier),
})
assert.NoError(t, err)
assert.Len(t, aul.Items, 0)
})
t.Run("without a valid user", func(t *testing.T) {
aul, err := client.AccountUsers.List(ctx, AccountUserListOptions{
User: String(badIdentifier),
})
assert.NoError(t, err)
assert.Len(t, aul.Items, 0)
})
}