-
Notifications
You must be signed in to change notification settings - Fork 1
/
watch_test.go
203 lines (199 loc) · 3.44 KB
/
watch_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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package main
import (
"bufio"
"io/ioutil"
"log"
"reflect"
"strings"
"testing"
)
func TestReadTracklist(t *testing.T) {
log.SetOutput(ioutil.Discard)
type cas struct {
payload string
want Playlist
err error
}
for n, c := range []cas{
{
payload: `file: Elliott Smith - Either-Or/11 - 2-45 am.mp3
Last-Modified: 2015-03-01T13:51:22Z
Artist: Elliott Smith
AlbumArtist: Elliott Smith
Title: 2:45 am
Album: Either/Or
Track: 11
Date: 1997
Genre: (81)
Time: 199
duration: 198.896
Pos: 0
Id: 79
file: Elliott Smith - Either-Or/12 - Say Yes.mp3
Last-Modified: 2015-03-01T13:51:30Z
Artist: Elliott Smith
AlbumArtist: Elliott Smith
Title: Say Yes
Album: Either/Or
Track: 12
Date: 1997
Genre: (81)
Time: 138
duration: 138.187
Pos: 1
Id: 80
OK
`,
want: Playlist{
{
ID: "79",
Pos: 0,
Track: Track{
ID: "Elliott Smith - Either-Or/11 - 2-45 am.mp3",
File: "11 - 2-45 am.mp3",
Artist: "Elliott Smith",
AlbumArtist: "Elliott Smith",
Title: "2:45 am",
Album: "Either/Or",
Track: "11",
Duration: 198.896,
},
},
{
ID: "80",
Pos: 1,
Track: Track{
ID: "Elliott Smith - Either-Or/12 - Say Yes.mp3",
File: "12 - Say Yes.mp3",
Artist: "Elliott Smith",
AlbumArtist: "Elliott Smith",
Title: "Say Yes",
Album: "Either/Or",
Track: "12",
Duration: 138.187,
},
},
},
},
{
payload: "OK\n",
want: Playlist{},
},
} {
kv, err := readKV(bufio.NewReader(strings.NewReader(c.payload)))
if have, want := err, c.err; !reflect.DeepEqual(have, want) {
t.Errorf("case %d: have %q, want %q", n, have, want)
continue
}
if c.err != nil {
continue
}
if have, want := readPlaylist(kv), c.want; !reflect.DeepEqual(have, want) {
t.Errorf("case %d: have %#v, want %#v", n, have, want)
}
}
}
func TestStatus(t *testing.T) {
log.SetOutput(ioutil.Discard)
type cas struct {
payload string
want Status
}
for n, c := range []cas{
// 0.16
{
payload: `volume: 61
repeat: 0
random: 0
single: 0
consume: 0
playlist: 184
playlistlength: 14
xfade: 0
mixrampdb: 0.000000
mixrampdelay: nan
state: play
song: 1
songid: 220
time: 38:213
elapsed: 37.918
bitrate: 256
audio: 44100:24:2
nextsong: 2
OK
`,
want: Status{
State: "play",
SongID: "220",
Elapsed: 37.918,
Duration: 213,
Volume: 61,
},
},
// 0.20
{
payload: `volume: 30
repeat: 0
random: 0
single: 0
consume: 0
playlist: 190
playlistlength: 1
mixrampdb: 0.000000
state: play
song: 0
songid: 505
time: 11:199
elapsed: 11.342
bitrate: 320
duration: 198.896
audio: 44100:24:2
OK
`,
want: Status{
State: "play",
SongID: "505",
Elapsed: 11.342,
Duration: 198.896,
Volume: 30,
},
},
// 0.20 stopped
{
payload: `volume: -1
repeat: 0
random: 0
single: 0
consume: 0
playlist: 206
playlistlength: 13
mixrampdb: 0.000000
state: stop
song: 5
songid: 705
nextsong: 6
nextsongid: 706
OK
`,
want: Status{
State: "stop",
SongID: "705",
Elapsed: 0,
Duration: 0,
Volume: -1,
},
},
} {
kv, err := readKVmap(bufio.NewReader(strings.NewReader(c.payload)))
if err != nil {
t.Fatal(err)
}
s, err := readStatus(kv)
if err != nil {
t.Fatal(err)
}
if have, want := s, c.want; !reflect.DeepEqual(have, want) {
t.Errorf("case %d: have %#v, want %#v", n, have, want)
}
}
}