-
Notifications
You must be signed in to change notification settings - Fork 14
/
lists_test.go
164 lines (156 loc) · 4.51 KB
/
lists_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
package subsonic
import (
"testing"
"time"
)
func runListsTests(client Client, t *testing.T) {
sampleGenre := getSampleGenre(client)
t.Run("GetAlbumList", func(t *testing.T) {
_, err := client.GetAlbumList("foobar", nil)
if err == nil {
t.Error("No error was returned with an invalid listType argument")
}
_, err = client.GetAlbumList("byYear", nil)
if err == nil {
t.Error("Failed to validate byYear parameters")
}
_, err = client.GetAlbumList("byYear", map[string]string{"fromYear": "1990"})
if err == nil {
t.Error("Failed to validate partial byYear parameters")
}
_, err = client.GetAlbumList("byGenre", nil)
if err == nil {
t.Error("Failed to validate byGenre parameters")
}
albums, err := client.GetAlbumList("random", nil)
if err != nil {
t.Error(err)
}
if albums == nil {
t.Error("No albums were returned in a call to random getAlbumList")
}
for _, album := range albums {
if album.Title == "" {
t.Errorf("Album %#v has an empty name :(", album)
}
}
// Work out genre matching
albums, err = client.GetAlbumList("byGenre", map[string]string{"genre": sampleGenre.Name})
if err != nil {
t.Error(err)
}
if albums == nil || len(albums) < 1 {
t.Error("No albums were returned in a call to a byGenre getAlbumList")
}
var empty time.Time
for _, album := range albums {
if album.Created == empty {
t.Errorf("Album %#v has empty created time", album)
}
}
})
t.Run("GetAlbumList2", func(t *testing.T) {
// Test incorrect parameters
_, err := client.GetAlbumList2("foobar", nil)
if err == nil {
t.Error("No error was returned with an invalid listType argument")
}
_, err = client.GetAlbumList2("byYear", nil)
if err == nil {
t.Error("Failed to validate byYear parameters")
}
_, err = client.GetAlbumList2("byYear", map[string]string{"fromYear": "1990"})
if err == nil {
t.Error("Failed to validate partial byYear parameters")
}
_, err = client.GetAlbumList2("byGenre", nil)
if err == nil {
t.Error("Failed to validate byGenre parameters")
}
// Test with proper parameters
albums, err := client.GetAlbumList2("newest", nil)
if err != nil {
t.Error(err)
}
if albums == nil {
t.Error("No albums were returned in a call to newest getAlbumList2")
}
var empty time.Time
for _, album := range albums {
if album.Name == "" {
t.Errorf("Album %#v has an empty name", album)
}
if album.Created == empty {
t.Errorf("Album %#v has empty created time", album)
}
}
})
t.Run("GetRandomSongs", func(t *testing.T) {
songs, err := client.GetRandomSongs(nil)
if err != nil || songs == nil {
t.Error("Basic call to getRandomSongs failed")
}
var empty time.Time
for _, song := range songs {
if song.Created == empty {
t.Errorf("Song %#v had an empty created", song)
}
}
songs, err = client.GetRandomSongs(map[string]string{"size": "1"})
if len(songs) != 1 {
t.Errorf("Limiting songs returned by getRandomSongs failed: expected 1, length actual %d", len(songs))
}
for _, song := range songs {
if song.Created == empty {
t.Errorf("Song %#v had an empty created", song)
}
}
})
t.Run("GetSongsByGenre", func(t *testing.T) {
songs, err := client.GetSongsByGenre(sampleGenre.Name, nil)
if err != nil {
t.Error(err)
}
if songs == nil {
t.Errorf("No songs returned for genre %v", sampleGenre)
}
songs, err = client.GetSongsByGenre(sampleGenre.Name, map[string]string{"count": "1"})
if err != nil {
t.Error(err)
}
if len(songs) != 1 {
t.Errorf("Limiting songs returned by GetSongsByGenre failed: expected 1, length actual %d", len(songs))
}
var empty time.Time
for _, song := range songs {
if song.Created == empty {
t.Errorf("Song %#v had an empty created", song)
}
}
})
t.Run("GetNowPlaying", func(t *testing.T) {
// This test is essentially a no-op because we can't depend on the state of playing something in a test environment
entries, err := client.GetNowPlaying()
if err != nil {
t.Error(err)
}
var empty time.Time
for _, nowPlaying := range entries {
//t.Logf("NowPlaying %d minutes ago, created %v", nowPlaying.MinutesAgo, nowPlaying.Created.Format("2006-01-02T15:04:05.999999-07:00"))
if nowPlaying.Created == empty {
t.Errorf("NowPlayingEntry %#v had an empty created", nowPlaying)
}
}
})
t.Run("GetStarred", func(t *testing.T) {
// State dependent test
_, err := client.GetStarred(nil)
if err != nil {
t.Error(err)
}
_, err = client.GetStarred2(nil)
if err != nil {
t.Error(err)
}
})
}