forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.go
89 lines (70 loc) · 1.8 KB
/
user_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
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
getUsersJSON = `[{"id":1,"email":"users@localhost","isAdmin":true}]`
getUserJSON = `{"id":2,"email":"user@localhost","isGrafanaAdmin":false}`
getUserByEmailJSON = `{"id":3,"email":"userByEmail@localhost","isGrafanaAdmin":true}`
getUserUpdateJSON = `{"id":4,"email":"userUpdate@localhost","isGrafanaAdmin":false}`
)
func TestUsers(t *testing.T) {
server, client := gapiTestTools(t, 200, getUsersJSON)
defer server.Close()
resp, err := client.Users()
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
if len(resp) != 1 {
t.Fatal("No users were returned.")
}
user := resp[0]
if user.Email != "users@localhost" ||
user.ID != 1 ||
user.IsAdmin != true {
t.Error("Not correctly parsing returned users.")
}
}
func TestUser(t *testing.T) {
server, client := gapiTestTools(t, 200, getUserJSON)
defer server.Close()
user, err := client.User(1)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(user))
if user.Email != "user@localhost" ||
user.ID != 2 ||
user.IsAdmin != false {
t.Error("Not correctly parsing returned user.")
}
}
func TestUserByEmail(t *testing.T) {
server, client := gapiTestTools(t, 200, getUserByEmailJSON)
defer server.Close()
user, err := client.UserByEmail("admin@localhost")
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(user))
if user.Email != "userByEmail@localhost" ||
user.ID != 3 ||
user.IsAdmin != true {
t.Error("Not correctly parsing returned user.")
}
}
func TestUserUpdate(t *testing.T) {
server, client := gapiTestTools(t, 200, getUserUpdateJSON)
defer server.Close()
user, err := client.User(4)
if err != nil {
t.Fatal(err)
}
user.IsAdmin = true
err = client.UserUpdate(user)
if err != nil {
t.Error(err)
}
}