forked from nytm/go-grafana-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.go
59 lines (47 loc) · 1.24 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
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
getUsersJSON = `[{"id":1,"name":"","login":"admin","email":"admin@localhost","avatarUrl":"/avatar/46d229b033af06a191ff2267bca9ae56","isAdmin":true,"lastSeenAt":"2018-06-28T14:42:24Z","lastSeenAtAge":"\u003c 1m"}]`
getUserByEmailJSON = `{"id":1,"email":"admin@localhost","name":"","login":"admin","theme":"","orgId":1,"isGrafanaAdmin":true}`
)
func TestUsers(t *testing.T) {
server, client := gapiTestTools(200, getUsersJSON)
defer server.Close()
resp, err := client.Users()
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(resp))
user := User{
Id: 1,
Email: "admin@localhost",
Name: "",
Login: "admin",
IsAdmin: true,
}
if len(resp) != 1 || resp[0] != user {
t.Error("Not correctly parsing returned users.")
}
}
func TestUserByEmail(t *testing.T) {
server, client := gapiTestTools(200, getUserByEmailJSON)
defer server.Close()
resp, err := client.UserByEmail("admin@localhost")
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(resp))
user := User{
Id: 1,
Email: "admin@localhost",
Name: "",
Login: "admin",
IsAdmin: true,
}
if resp != user {
t.Error("Not correctly parsing returned user.")
}
}