forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_key_test.go
68 lines (54 loc) · 1.16 KB
/
api_key_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
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
createAPIKeyJSON = `{"name":"key-name", "key":"mock-api-key"}`
deleteAPIKeyJSON = `{"message":"API key deleted"}`
getAPIKeysJSON = `[
{
"id": 1,
"name": "key-name-2",
"role": "Viewer"
},
{
"id": 2,
"name": "key-name-2",
"role": "Admin",
"expiration": "2021-10-30T10:52:03+03:00"
}
]`
)
func TestCreateAPIKey(t *testing.T) {
server, client := gapiTestTools(t, 200, createAPIKeyJSON)
defer server.Close()
req := CreateAPIKeyRequest{
Name: "key-name",
Role: "Viewer",
SecondsToLive: 0,
}
res, err := client.CreateAPIKey(req)
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(res))
}
func TestDeleteAPIKey(t *testing.T) {
server, client := gapiTestTools(t, 200, deleteAPIKeyJSON)
defer server.Close()
res, err := client.DeleteAPIKey(int64(1))
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(res))
}
func TestGetAPIKeys(t *testing.T) {
server, client := gapiTestTools(t, 200, getAPIKeysJSON)
defer server.Close()
res, err := client.GetAPIKeys(true)
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(res))
}