forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
team_test.go
77 lines (62 loc) · 1.93 KB
/
team_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
67
68
69
70
71
72
73
74
75
76
77
package dtrack
import (
"context"
"github.com/stretchr/testify/require"
"testing"
)
func TestGenerateAPIKey(t *testing.T) {
client := setUpContainer(t, testContainerOptions{
APIPermissions: []string{
PermissionAccessManagement,
},
})
team, err := client.Team.Create(context.Background(), Team{
Name: "GenerateAPIKey",
})
require.NoError(t, err)
key, err := client.Team.GenerateAPIKey(context.Background(), team.UUID)
require.NoError(t, err)
keys, err := client.Team.GetAPIKeys(context.Background(), team.UUID)
require.NoError(t, err)
require.Equal(t, len(keys), 1)
require.Equal(t, keys[0].Key, key)
}
func TestDeleteAPIKey(t *testing.T) {
client := setUpContainer(t, testContainerOptions{
APIPermissions: []string{
PermissionAccessManagement,
},
})
team, err := client.Team.Create(context.Background(), Team{
Name: "DeleteAPIKey",
})
require.NoError(t, err)
key, err := client.Team.GenerateAPIKey(context.Background(), team.UUID)
require.NoError(t, err)
err = client.Team.DeleteAPIKey(context.Background(), key)
require.NoError(t, err)
keys, err := client.Team.GetAPIKeys(context.Background(), team.UUID)
require.NoError(t, err)
require.Empty(t, keys)
}
func TestUpdateAPIKeyComment(t *testing.T) {
client := setUpContainer(t, testContainerOptions{
APIPermissions: []string{
PermissionAccessManagement,
},
})
team, err := client.Team.Create(context.Background(), Team{
Name: "UpdateAPIKeyComment",
})
require.NoError(t, err)
key, err := client.Team.GenerateAPIKey(context.Background(), team.UUID)
require.NoError(t, err)
comment, err := client.Team.UpdateAPIKeyComment(context.Background(), key, "test-comment")
require.NoError(t, err)
require.Equal(t, comment, "test-comment")
keys, err := client.Team.GetAPIKeys(context.Background(), team.UUID)
require.NoError(t, err)
require.Equal(t, len(keys), 1)
require.Equal(t, keys[0].Key, key)
require.Equal(t, keys[0].Comment, "test-comment")
}