forked from grafana-tools/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest-folder_integration_test.go
88 lines (75 loc) · 1.77 KB
/
rest-folder_integration_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
package sdk_test
import (
"context"
"testing"
"github.com/grafana-tools/sdk"
)
func Test_Folder_CRUD(t *testing.T) {
shouldSkip(t)
client := getClient(t)
ctx := context.Background()
var f1 = sdk.Folder{
Title: "test-folder-1",
}
var err error
fReceived1, err := client.CreateFolder(ctx, f1)
if err != nil {
t.Fatal(err)
}
if fReceived1.Title != f1.Title {
t.Fatalf("got wrong title: expected %s, was %s", f1.Title, fReceived1.Title)
}
var f2 = sdk.Folder{
Title: "test-folder-2",
}
fReceived2, err := client.CreateFolder(ctx, f2)
if err != nil {
t.Fatal(err)
}
if fReceived2.Title != f2.Title {
t.Fatalf("got wrong title: expected %s, was %s", f2.Title, fReceived2.Title)
}
fs, err := client.GetAllFolders(ctx, sdk.Limit(1))
if err != nil {
t.Fatal(err)
}
if len(fs) != 1 {
t.Fatalf("expected to get one folders, got %d", len(fs))
}
fg, err := client.GetFolderByUID(ctx, fReceived1.UID)
if err != nil {
t.Fatal(err)
}
if fReceived1.Title != fg.Title {
t.Fatalf("got wrong title: expected %s, was %s", fReceived1.Title, fg.Title)
}
fg, err = client.GetFolderByID(ctx, fReceived1.ID)
if err != nil {
t.Fatal(err)
}
if fReceived1.Title != fg.Title {
t.Fatalf("got wrong title: expected %s, was %s", fReceived1.Title, fg.Title)
}
fReceived1.Title = "test-update-folder"
fg, err = client.UpdateFolderByUID(ctx, fReceived1)
if err != nil {
t.Fatal(err)
}
if fReceived1.Title != fg.Title {
t.Fatalf("got wrong title: expected %s, was %s", fReceived1.Title, fg.Title)
}
r, err := client.DeleteFolderByUID(ctx, fReceived1.UID)
if err != nil {
t.Fatal(err)
}
if !r {
t.Fatal("delete failed")
}
r, err = client.DeleteFolderByUID(ctx, fReceived2.UID)
if err != nil {
t.Fatal(err)
}
if !r {
t.Fatal("delete failed")
}
}