forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot_test.go
47 lines (38 loc) · 880 Bytes
/
snapshot_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
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
createdSnapshotResponse = `{
"deleteKey":"XXXXXXX",
"deleteUrl":"myurl/api/snapshots-delete/XXXXXXX",
"key":"YYYYYYY",
"url":"myurl/dashboard/snapshot/YYYYYYY",
"id": 1
}`
)
func TestSnapshotCreate(t *testing.T) {
client := gapiTestTools(t, 200, createdSnapshotResponse)
snapshot := Snapshot{
Model: map[string]interface{}{
"title": "test",
},
Expires: 3600,
}
resp, err := client.NewSnapshot(snapshot)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp.DeleteKey != "XXXXXXX" {
t.Errorf("Invalid key - %s, Expected %s", resp.DeleteKey, "XXXXXXX")
}
for _, code := range []int{400, 401, 403, 412} {
client = gapiTestTools(t, code, "error")
_, err = client.NewSnapshot(snapshot)
if err == nil {
t.Errorf("%d not detected", code)
}
}
}