-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathkeys_test.go
75 lines (64 loc) · 1.72 KB
/
keys_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
package sentry
import (
"testing"
)
func TestKeysResource(t *testing.T) {
t.Parallel()
client := newTestClient(t)
org, err := client.GetOrganization(getDefaultOrg())
if err != nil {
t.Fatal(err)
}
team, cleanup := createTeamHelper(t)
defer cleanup()
project, cleanupproj := createProjectHelper(t, team)
defer cleanupproj()
t.Run("Create a new key for project", func(t *testing.T) {
key, err := client.CreateClientKey(org, project, "Test client key")
if err != nil {
t.Error(err)
}
if key.Label != "Test client key" {
t.Error("Key does not have correct label")
}
if key.RateLimit != nil {
t.Error("freshly created keys should not have rate limiting")
}
t.Run("List client keys", func(t *testing.T) {
keys, err := client.GetClientKeys(org, project)
if err != nil {
t.Error(err)
}
if len(keys) != 2 {
t.Errorf("Expected 2 keys, got %d", len(keys))
}
})
t.Run("Update rate limit for client key", func(t *testing.T) {
resKey, err := client.SetClientKeyRateLimit(org, project, key, 1000, 60)
if err != nil {
t.Error(err)
}
if resKey.RateLimit == nil {
t.Error("missing rate limit in updated key")
}
if resKey.RateLimit.Count != 1000 || resKey.RateLimit.Window != 60 {
t.Error("failed to apply rate limit for key")
}
})
t.Run("Update name of client key", func(t *testing.T) {
key, err = client.UpdateClientKey(org, project, key, "This is a new name")
if err != nil {
t.Error(err)
}
if key.Label != "This is a new name" {
t.Error("Failed to update to a new name")
}
t.Run("Deleting the client key", func(t *testing.T) {
err := client.DeleteClientKey(org, project, key)
if err != nil {
t.Error(err)
}
})
})
})
}