forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
org_users_test.go
97 lines (76 loc) · 2.06 KB
/
org_users_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
getOrgUsersJSON = `[{"orgID":1,"userID":1,"email":"admin@localhost","avatarUrl":"/avatar/46d229b033af06a191ff2267bca9ae56","login":"admin","role":"Admin","lastSeenAt":"2018-06-28T14:16:11Z","lastSeenAtAge":"\u003c 1m"}]`
addOrgUserJSON = `{"message":"User added to organization"}`
updateOrgUserJSON = `{"message":"Organization user updated"}`
removeOrgUserJSON = `{"message":"User removed from organization"}`
)
func TestOrgUsersCurrent(t *testing.T) {
server, client := gapiTestTools(t, 200, getOrgUsersJSON)
defer server.Close()
resp, err := client.OrgUsersCurrent()
if err != nil {
t.Fatal(err)
}
user := OrgUser{
OrgID: 1,
UserID: 1,
Email: "admin@localhost",
Login: "admin",
Role: "Admin",
}
if resp[0] != user {
t.Error("Not correctly parsing returned organization users.")
}
}
func TestOrgUsers(t *testing.T) {
server, client := gapiTestTools(t, 200, getOrgUsersJSON)
defer server.Close()
org := int64(1)
resp, err := client.OrgUsers(org)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
user := OrgUser{
OrgID: 1,
UserID: 1,
Email: "admin@localhost",
Login: "admin",
Role: "Admin",
}
if resp[0] != user {
t.Error("Not correctly parsing returned organization users.")
}
}
func TestAddOrgUser(t *testing.T) {
server, client := gapiTestTools(t, 200, addOrgUserJSON)
defer server.Close()
orgID, user, role := int64(1), "admin@localhost", "Admin"
err := client.AddOrgUser(orgID, user, role)
if err != nil {
t.Fatal(err)
}
}
func TestUpdateOrgUser(t *testing.T) {
server, client := gapiTestTools(t, 200, updateOrgUserJSON)
defer server.Close()
orgID, userID, role := int64(1), int64(1), "Editor"
err := client.UpdateOrgUser(orgID, userID, role)
if err != nil {
t.Fatal(err)
}
}
func TestRemoveOrgUser(t *testing.T) {
server, client := gapiTestTools(t, 200, removeOrgUserJSON)
defer server.Close()
orgID, userID := int64(1), int64(1)
err := client.RemoveOrgUser(orgID, userID)
if err != nil {
t.Error(err)
}
}