This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
playlist_test.go
102 lines (87 loc) · 1.72 KB
/
playlist_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
package gapi
import (
"testing"
)
const (
createAndUpdatePlaylistResponse = ` {
"uid": "1",
"name": "my playlist",
"interval": "5m"
}`
getPlaylistResponse = `{
"uid": "2",
"name": "my playlist",
"interval": "5m",
"orgId": "my org",
"items": [
{
"id": 1,
"playlistId": 1,
"type": "dashboard_by_id",
"value": "3",
"order": 1,
"title":"my dasboard"
},
{
"id": 1,
"playlistId": 1,
"type": "dashboard_by_id",
"value": "3",
"order": 1,
"title":"my dasboard"
}
]
}`
)
func TestPlaylistCreateAndUpdate(t *testing.T) {
client := gapiTestToolsFromCalls(t, []mockServerCall{
{200, createAndUpdatePlaylistResponse},
{200, createAndUpdatePlaylistResponse},
})
playlist := Playlist{
Name: "my playlist",
Interval: "5m",
Items: []PlaylistItem{
{},
},
}
// create
id, err := client.NewPlaylist(playlist)
if err != nil {
t.Fatal(err)
}
if id != "1" {
t.Errorf("Invalid id - %s, Expected %s", id, "1")
}
// update
playlist.Items = append(playlist.Items, PlaylistItem{
Type: "dashboard_by_id",
Value: "1",
Order: 1,
Title: "my dashboard",
})
err = client.UpdatePlaylist(playlist)
if err != nil {
t.Fatal(err)
}
}
func TestGetPlaylist(t *testing.T) {
client := gapiTestTools(t, 200, getPlaylistResponse)
playlist, err := client.Playlist("2")
if err != nil {
t.Fatal(err)
}
if playlist.UID != "2" {
t.Errorf("Invalid id - %s, Expected %s", playlist.UID, "2")
}
if len(playlist.Items) != 2 {
t.Errorf("Invalid len(items) - %d, Expected %d", len(playlist.Items), 2)
}
}
func TestDeletePlaylist(t *testing.T) {
client := gapiTestTools(t, 200, "")
err := client.DeletePlaylist("1")
if err != nil {
t.Fatal(err)
}
}