forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
folder_test.go
174 lines (151 loc) · 3.45 KB
/
folder_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
getFoldersJSON = `
[
{
"id":1,
"uid": "nErXDvCkzz",
"title": "Departmenet ABC",
"url": "/dashboards/f/nErXDvCkzz/department-abc",
"hasAcl": false,
"canSave": true,
"canEdit": true,
"canAdmin": true,
"createdBy": "admin",
"created": "2018-01-31T17:43:12+01:00",
"updatedBy": "admin",
"updated": "2018-01-31T17:43:12+01:00",
"version": 1
}
]
`
getFolderJSON = `
{
"id":1,
"uid": "nErXDvCkzz",
"title": "Departmenet ABC",
"url": "/dashboards/f/nErXDvCkzz/department-abc",
"hasAcl": false,
"canSave": true,
"canEdit": true,
"canAdmin": true,
"createdBy": "admin",
"created": "2018-01-31T17:43:12+01:00",
"updatedBy": "admin",
"updated": "2018-01-31T17:43:12+01:00",
"version": 1
}
`
createdFolderJSON = `
{
"id":1,
"uid": "nErXDvCkzz",
"title": "Departmenet ABC",
"url": "/dashboards/f/nErXDvCkzz/department-abc",
"hasAcl": false,
"canSave": true,
"canEdit": true,
"canAdmin": true,
"createdBy": "admin",
"created": "2018-01-31T17:43:12+01:00",
"updatedBy": "admin",
"updated": "2018-01-31T17:43:12+01:00",
"version": 1
}
`
updatedFolderJSON = `
{
"id":1,
"uid": "nErXDvCkzz",
"title": "Departmenet DEF",
"url": "/dashboards/f/nErXDvCkzz/department-def",
"hasAcl": false,
"canSave": true,
"canEdit": true,
"canAdmin": true,
"createdBy": "admin",
"created": "2018-01-31T17:43:12+01:00",
"updatedBy": "admin",
"updated": "2018-01-31T17:43:12+01:00",
"version": 1
}
`
deletedFolderJSON = `
{
"message":"Folder deleted"
}
`
)
func TestFolders(t *testing.T) {
server, client := gapiTestTools(t, 200, getFoldersJSON)
defer server.Close()
folders, err := client.Folders()
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(folders))
if len(folders) != 1 {
t.Error("Length of returned folders should be 1")
}
if folders[0].ID != 1 || folders[0].Title != "Departmenet ABC" {
t.Error("Not correctly parsing returned folders.")
}
}
func TestFolder(t *testing.T) {
server, client := gapiTestTools(t, 200, getFolderJSON)
defer server.Close()
folder := int64(1)
resp, err := client.Folder(folder)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp.ID != folder || resp.Title != "Departmenet ABC" {
t.Error("Not correctly parsing returned folder.")
}
}
func TestFolderByUid(t *testing.T) {
server, client := gapiTestTools(t, 200, getFolderJSON)
defer server.Close()
folder := "nErXDvCkzz"
resp, err := client.FolderByUID(folder)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp.UID != folder || resp.Title != "Departmenet ABC" {
t.Error("Not correctly parsing returned folder.")
}
}
func TestNewFolder(t *testing.T) {
server, client := gapiTestTools(t, 200, createdFolderJSON)
defer server.Close()
resp, err := client.NewFolder("test-folder")
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp.UID != "nErXDvCkzz" {
t.Error("Not correctly parsing returned creation message.")
}
}
func TestUpdateFolder(t *testing.T) {
server, client := gapiTestTools(t, 200, updatedFolderJSON)
defer server.Close()
err := client.UpdateFolder("nErXDvCkzz", "test-folder")
if err != nil {
t.Fatal(err)
}
}
func TestDeleteFolder(t *testing.T) {
server, client := gapiTestTools(t, 200, deletedFolderJSON)
defer server.Close()
err := client.DeleteFolder("nErXDvCkzz")
if err != nil {
t.Fatal(err)
}
}