This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
playlist_test.go
102 lines (87 loc) · 1.71 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 = ` {
"id": 1,
"name": "my playlist",
"interval": "5m"
}`
getPlaylistResponse = `{
"id" : 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) {
server, client := gapiTestTools(200, createAndUpdatePlaylistResponse)
defer server.Close()
playlist := Playlist{
Name: "my playlist",
Interval: "5m",
Items: []PlaylistItem{
PlaylistItem{},
},
}
// create
id, err := client.NewPlaylist(playlist)
if err != nil {
t.Fatal(err)
}
if id != 1 {
t.Errorf("Invalid id - %d, Expected %d", 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) {
server, client := gapiTestTools(200, getPlaylistResponse)
defer server.Close()
playlist, err := client.Playlist(1)
if err != nil {
t.Error(err)
}
if playlist.Id != 2 {
t.Errorf("Invalid id - %d, Expected %d", playlist.Id, 1)
}
if len(playlist.Items) != 2 {
t.Errorf("Invalid len(items) - %d, Expected %d", len(playlist.Items), 2)
}
}
func TestDeletePlaylist(t *testing.T) {
server, client := gapiTestTools(200, "")
defer server.Close()
err := client.DeletePlaylist(1)
if err != nil {
t.Error(err)
}
}