forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_test.go
96 lines (78 loc) · 2.08 KB
/
admin_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
package gapi
import (
"strings"
"testing"
"github.com/gobs/pretty"
)
const (
createUserJSON = `{"id":1,"message":"User created"}`
deleteUserJSON = `{"message":"User deleted"}`
updateUserPasswordJSON = `{"message":"User password updated"}`
updateUserPermissionsJSON = `{"message":"User permissions updated"}`
pauseAllAlertsJSON = `{
"alertsAffected": 1,
"state": "Paused",
"message": "alert paused"
}`
)
func TestCreateUser(t *testing.T) {
server, client := gapiTestTools(t, 200, createUserJSON)
defer server.Close()
user := User{
Email: "admin@localhost",
Login: "admin",
Name: "Administrator",
Password: "password",
}
resp, err := client.CreateUser(user)
if err != nil {
t.Error(err)
}
if resp != 1 {
t.Error("Not correctly parsing returned user message.")
}
}
func TestDeleteUser(t *testing.T) {
server, client := gapiTestTools(t, 200, deleteUserJSON)
defer server.Close()
err := client.DeleteUser(int64(1))
if err != nil {
t.Error(err)
}
}
func TestUpdateUserPassword(t *testing.T) {
server, client := gapiTestTools(t, 200, updateUserPasswordJSON)
defer server.Close()
err := client.UpdateUserPassword(int64(1), "new-password")
if err != nil {
t.Error(err)
}
}
func TestUpdateUserPermissions(t *testing.T) {
server, client := gapiTestTools(t, 200, updateUserPermissionsJSON)
defer server.Close()
err := client.UpdateUserPermissions(int64(1), false)
if err != nil {
t.Error(err)
}
}
func TestPauseAllAlerts(t *testing.T) {
server, client := gapiTestTools(t, 200, pauseAllAlertsJSON)
defer server.Close()
res, err := client.PauseAllAlerts()
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(res))
if res.State != "Paused" {
t.Error("pause all alerts response should contain the correct response message")
}
}
func TestPauseAllAlerts_500(t *testing.T) {
server, client := gapiTestTools(t, 500, pauseAllAlertsJSON)
defer server.Close()
_, err := client.PauseAllAlerts()
if !strings.Contains(err.Error(), "status: 500") {
t.Errorf("expected error to contain 'status: 500'; got: %s", err.Error())
}
}