forked from grafana-tools/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest-admin_integration_test.go
55 lines (45 loc) · 1.26 KB
/
rest-admin_integration_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
package sdk_test
import (
"context"
"testing"
"github.com/grafana-tools/sdk"
)
func TestAdminOperations(t *testing.T) {
shouldSkip(t)
client := getClient(t)
ctx := context.Background()
u := sdk.User{
Login: "test",
Name: "name",
Email: "[email protected]",
Theme: "",
Password: "vvvvvvvvvvvv",
IsGrafanaAdmin: false,
}
st, err := client.CreateUser(ctx, u)
if err != nil {
t.Fatalf("failed to create an user: %s", err.Error())
}
if st.Message != nil && *st.Message == "failed to create user" {
t.Fatal("failed to create an user for some unknown reason")
}
uid := *st.ID
retrievedUser, err := client.GetUser(ctx, uid)
if err != nil {
t.Fatalf("failed to get user: %s", err.Error())
}
if retrievedUser.Login != u.Login || retrievedUser.Email != u.Email {
t.Fatal("retrieved data does not match what was created")
}
_, err = client.UpdateUserPermissions(ctx, sdk.UserPermissions{IsGrafanaAdmin: true}, uid)
if err != nil {
t.Fatalf("failed to convert the user into an admin: %s", err)
}
retrievedUser, err = client.GetUser(ctx, uid)
if err != nil {
t.Fatalf("failed to get user: %s", err.Error())
}
if retrievedUser.IsGrafanaAdmin != true {
t.Fatal("user should be an admin but is not")
}
}