-
Notifications
You must be signed in to change notification settings - Fork 0
/
types_test.go
752 lines (656 loc) · 26 KB
/
types_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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
package mpris
import (
"fmt"
"testing"
"time"
"github.com/godbus/dbus/v5"
"github.com/stretchr/testify/assert"
)
func TestMetadata_MPRISTrackID(t *testing.T) {
var expectedTrackID dbus.ObjectPath
var expectedErrorText string
var trackID dbus.ObjectPath
var err error
//happycase
expectedTrackID = "/my/path"
expectedErrorText = "<nil>"
trackID, err = Metadata{
"mpris:trackid": dbus.MakeVariant(dbus.ObjectPath("/my/path")),
}.MPRISTrackID()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedTrackID, trackID, "unexpected trackID")
//not present
expectedTrackID = ""
expectedErrorText = "<nil>"
trackID, err = Metadata{}.MPRISTrackID()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedTrackID, trackID, "unexpected trackID")
//unexpected type
expectedTrackID = ""
expectedErrorText = "int could not be parsed to dbus.ObjectPath: the given type is not as expected"
trackID, err = Metadata{
"mpris:trackid": dbus.MakeVariant(123456789),
}.MPRISTrackID()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedTrackID, trackID, "unexpected trackID")
}
func TestMetadata_MPRISLength(t *testing.T) {
var expectedLength int64
var expectedErrorText string
var length int64
var err error
//happycase
expectedLength = 42
expectedErrorText = "<nil>"
length, err = Metadata{
"mpris:length": dbus.MakeVariant(int64(42)),
}.MPRISLength()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedLength, length, "unexpected length")
//not present
expectedLength = 0
expectedErrorText = "<nil>"
length, err = Metadata{}.MPRISLength()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedLength, length, "unexpected length")
//unexpected type
expectedLength = 0
expectedErrorText = "string could not be parsed to int64: the given type is not as expected"
length, err = Metadata{
"mpris:length": dbus.MakeVariant("nope"),
}.MPRISLength()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedLength, length, "unexpected length")
}
func TestMetadata_MPRISArtURL(t *testing.T) {
var expectedArtURL string
var expectedErrorText string
var artURL string
var err error
//happycase
expectedArtURL = "/my/url"
expectedErrorText = "<nil>"
artURL, err = Metadata{
"mpris:artUrl": dbus.MakeVariant("/my/url"),
}.MPRISArtURL()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedArtURL, artURL, "unexpected artURL")
//not present
expectedArtURL = ""
expectedErrorText = "<nil>"
artURL, err = Metadata{}.MPRISArtURL()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedArtURL, artURL, "unexpected artURL")
//unexpected type
expectedArtURL = ""
expectedErrorText = "int could not be parsed to string: the given type is not as expected"
artURL, err = Metadata{
"mpris:artUrl": dbus.MakeVariant(42),
}.MPRISArtURL()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedArtURL, artURL, "unexpected artURL")
}
func TestMetadata_XESAMAlbum(t *testing.T) {
var expectedAlbum string
var expectedErrorText string
var album string
var err error
//happycase
expectedAlbum = "/my/url"
expectedErrorText = "<nil>"
album, err = Metadata{
"xesam:album": dbus.MakeVariant("/my/url"),
}.XESAMAlbum()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAlbum, album, "unexpected album")
//not present
expectedAlbum = ""
expectedErrorText = "<nil>"
album, err = Metadata{}.XESAMAlbum()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAlbum, album, "unexpected album")
//unexpected type
expectedAlbum = ""
expectedErrorText = "int could not be parsed to string: the given type is not as expected"
album, err = Metadata{
"xesam:album": dbus.MakeVariant(42),
}.XESAMAlbum()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAlbum, album, "unexpected album")
}
func TestMetadata_XESAMAlbumArtist(t *testing.T) {
var expectedAlbumArtist []string
var expectedErrorText string
var albumArtist []string
var err error
//happycase
expectedAlbumArtist = []string{"artist1", "artist2"}
expectedErrorText = "<nil>"
albumArtist, err = Metadata{
"xesam:albumArtist": dbus.MakeVariant([]string{"artist1", "artist2"}),
}.XESAMAlbumArtist()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAlbumArtist, albumArtist, "unexpected albumArtist")
//not present
expectedAlbumArtist = nil
expectedErrorText = "<nil>"
albumArtist, err = Metadata{}.XESAMAlbumArtist()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAlbumArtist, albumArtist, "unexpected albumArtist")
//unexpected type
expectedAlbumArtist = nil
expectedErrorText = "int could not be parsed to []string: the given type is not as expected"
albumArtist, err = Metadata{
"xesam:albumArtist": dbus.MakeVariant(42),
}.XESAMAlbumArtist()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAlbumArtist, albumArtist, "unexpected albumArtist")
}
func TestMetadata_XESAMArtist(t *testing.T) {
var expectedArtist []string
var expectedErrorText string
var artist []string
var err error
//happycase
expectedArtist = []string{"artist1", "artist2"}
expectedErrorText = "<nil>"
artist, err = Metadata{
"xesam:artist": dbus.MakeVariant([]string{"artist1", "artist2"}),
}.XESAMArtist()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedArtist, artist, "unexpected artist")
//not present
expectedArtist = nil
expectedErrorText = "<nil>"
artist, err = Metadata{}.XESAMArtist()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedArtist, artist, "unexpected artist")
//unexpected type
expectedArtist = nil
expectedErrorText = "int could not be parsed to []string: the given type is not as expected"
artist, err = Metadata{
"xesam:artist": dbus.MakeVariant(42),
}.XESAMArtist()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedArtist, artist, "unexpected artist")
}
func TestMetadata_XESAMAsText(t *testing.T) {
var expectedAsText string
var expectedErrorText string
var asText string
var err error
//happycase
expectedAsText = "asText"
expectedErrorText = "<nil>"
asText, err = Metadata{
"xesam:asText": dbus.MakeVariant("asText"),
}.XESAMAsText()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAsText, asText, "unexpected asText")
//not present
expectedAsText = ""
expectedErrorText = "<nil>"
asText, err = Metadata{}.XESAMAsText()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAsText, asText, "unexpected asText")
//unexpected type
expectedAsText = ""
expectedErrorText = "int could not be parsed to string: the given type is not as expected"
asText, err = Metadata{
"xesam:asText": dbus.MakeVariant(42),
}.XESAMAsText()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAsText, asText, "unexpected asText")
}
func TestMetadata_XESAMAudioBPM(t *testing.T) {
var expectedAudioBPM int
var expectedErrorText string
var audioBPM int
var err error
//happycase
expectedAudioBPM = 4711
expectedErrorText = "<nil>"
audioBPM, err = Metadata{
"xesam:audioBPM": dbus.MakeVariant(4711),
}.XESAMAudioBPM()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAudioBPM, audioBPM, "unexpected audioBPM")
//not present
expectedAudioBPM = 0
expectedErrorText = "<nil>"
audioBPM, err = Metadata{}.XESAMAudioBPM()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAudioBPM, audioBPM, "unexpected audioBPM")
//unexpected type
expectedAudioBPM = 0
expectedErrorText = "string could not be parsed to int: the given type is not as expected"
audioBPM, err = Metadata{
"xesam:audioBPM": dbus.MakeVariant("string"),
}.XESAMAudioBPM()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAudioBPM, audioBPM, "unexpected audioBPM")
}
func TestMetadata_XESAMAutoRating(t *testing.T) {
var expectedAutoRating float64
var expectedErrorText string
var autoRating float64
var err error
//happycase
expectedAutoRating = 4711
expectedErrorText = "<nil>"
autoRating, err = Metadata{
"xesam:autoRating": dbus.MakeVariant(float64(4711)),
}.XESAMAutoRating()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAutoRating, autoRating, "unexpected autoRating")
//not present
expectedAutoRating = 0
expectedErrorText = "<nil>"
autoRating, err = Metadata{}.XESAMAutoRating()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAutoRating, autoRating, "unexpected autoRating")
//unexpected type
expectedAutoRating = 0
expectedErrorText = "string could not be parsed to float64: the given type is not as expected"
autoRating, err = Metadata{
"xesam:autoRating": dbus.MakeVariant("string"),
}.XESAMAutoRating()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedAutoRating, autoRating, "unexpected autoRating")
}
func TestMetadata_XESAMComment(t *testing.T) {
var expectedComment []string
var expectedErrorText string
var comment []string
var err error
//happycase
expectedComment = []string{"comment1", "comment2"}
expectedErrorText = "<nil>"
comment, err = Metadata{
"xesam:comment": dbus.MakeVariant([]string{"comment1", "comment2"}),
}.XESAMComment()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedComment, comment, "unexpected comment")
//not present
expectedComment = nil
expectedErrorText = "<nil>"
comment, err = Metadata{}.XESAMComment()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedComment, comment, "unexpected comment")
//unexpected type
expectedComment = nil
expectedErrorText = "string could not be parsed to []string: the given type is not as expected"
comment, err = Metadata{
"xesam:comment": dbus.MakeVariant("string"),
}.XESAMComment()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedComment, comment, "unexpected comment")
}
func TestMetadata_XESAMComposer(t *testing.T) {
var expectedComment []string
var expectedErrorText string
var comment []string
var err error
//happycase
expectedComment = []string{"comment1", "comment2"}
expectedErrorText = "<nil>"
comment, err = Metadata{
"xesam:composer": dbus.MakeVariant([]string{"comment1", "comment2"}),
}.XESAMComposer()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedComment, comment, "unexpected comment")
//not present
expectedComment = nil
expectedErrorText = "<nil>"
comment, err = Metadata{}.XESAMComposer()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedComment, comment, "unexpected comment")
//unexpected type
expectedComment = nil
expectedErrorText = "string could not be parsed to []string: the given type is not as expected"
comment, err = Metadata{
"xesam:composer": dbus.MakeVariant("string"),
}.XESAMComposer()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedComment, comment, "unexpected comment")
}
func TestMetadata_XESAMContentCreated(t *testing.T) {
var expectedContentCreated time.Time
var expectedErrorText string
var contentCreated time.Time
var err error
//happycase
expectedContentCreated = time.Date(2007, 4, 29, 13, 56, 0, 0, time.UTC)
expectedErrorText = "<nil>"
contentCreated, err = Metadata{
"xesam:contentCreated": dbus.MakeVariant("2007-04-29T13:56+00:00"),
}.XESAMContentCreated()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedContentCreated.Equal(contentCreated), "unexpected contentCreated", expectedContentCreated, contentCreated)
//not present
expectedContentCreated = time.Time{}
expectedErrorText = "<nil>"
contentCreated, err = Metadata{}.XESAMContentCreated()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedContentCreated.Equal(contentCreated), "unexpected contentCreated", expectedContentCreated, contentCreated)
//unexpected type
expectedContentCreated = time.Time{}
expectedErrorText = "int could not be parsed to string: the given type is not as expected"
contentCreated, err = Metadata{
"xesam:contentCreated": dbus.MakeVariant(42),
}.XESAMContentCreated()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedContentCreated.Equal(contentCreated), "unexpected contentCreated", expectedContentCreated, contentCreated)
//unexpected date format
expectedContentCreated = time.Time{}
expectedErrorText = `cound not parse time: parsing time "not a date-time" as "2006-01-02T15:04-07:00": cannot parse "not a date-time" as "2006": the given type is not as expected`
contentCreated, err = Metadata{
"xesam:contentCreated": dbus.MakeVariant("not a date-time"),
}.XESAMContentCreated()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedContentCreated.Equal(contentCreated), "unexpected contentCreated", expectedContentCreated, contentCreated)
}
func TestMetadata_XESAMDiscNumber(t *testing.T) {
var expectedDiscNumber int
var expectedErrorText string
var discNumber int
var err error
//happycase
expectedDiscNumber = 42
expectedErrorText = "<nil>"
discNumber, err = Metadata{
"xesam:discNumber": dbus.MakeVariant(42),
}.XESAMDiscNumber()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedDiscNumber, discNumber, "unexpected discNumber")
//not present
expectedDiscNumber = 0
expectedErrorText = "<nil>"
discNumber, err = Metadata{}.XESAMDiscNumber()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedDiscNumber, discNumber, "unexpected discNumber")
//unexpected type
expectedDiscNumber = 0
expectedErrorText = "string could not be parsed to int: the given type is not as expected"
discNumber, err = Metadata{
"xesam:discNumber": dbus.MakeVariant("string"),
}.XESAMDiscNumber()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedDiscNumber, discNumber, "unexpected discNumber")
}
func TestMetadata_XESAMFirstUsed(t *testing.T) {
var expectedFirstUsed time.Time
var expectedErrorText string
var firstUsed time.Time
var err error
//happycase
expectedFirstUsed = time.Date(2007, 4, 29, 13, 56, 0, 0, time.FixedZone("", 0))
expectedErrorText = "<nil>"
firstUsed, err = Metadata{
"xesam:firstUsed": dbus.MakeVariant("2007-04-29T13:56+00:00"),
}.XESAMFirstUsed()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedFirstUsed.Equal(firstUsed), "unexpected firstUsed", expectedFirstUsed, firstUsed)
//not present
expectedFirstUsed = time.Time{}
expectedErrorText = "<nil>"
firstUsed, err = Metadata{}.XESAMFirstUsed()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedFirstUsed.Equal(firstUsed), "unexpected firstUsed", expectedFirstUsed, firstUsed)
//unexpected type
expectedFirstUsed = time.Time{}
expectedErrorText = "int could not be parsed to string: the given type is not as expected"
firstUsed, err = Metadata{
"xesam:firstUsed": dbus.MakeVariant(42),
}.XESAMFirstUsed()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedFirstUsed.Equal(firstUsed), "unexpected firstUsed", expectedFirstUsed, firstUsed)
//unexpected date format
expectedFirstUsed = time.Time{}
expectedErrorText = `cound not parse time: parsing time "not a date-time" as "2006-01-02T15:04-07:00": cannot parse "not a date-time" as "2006": the given type is not as expected`
firstUsed, err = Metadata{
"xesam:firstUsed": dbus.MakeVariant("not a date-time"),
}.XESAMFirstUsed()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedFirstUsed.Equal(firstUsed), "unexpected firstUsed", expectedFirstUsed, firstUsed)
}
func TestMetadata_XESAMGenre(t *testing.T) {
var expectedGenre []string
var expectedErrorText string
var genre []string
var err error
//happycase
expectedGenre = []string{"genre1", "genre2"}
expectedErrorText = "<nil>"
genre, err = Metadata{
"xesam:genre": dbus.MakeVariant([]string{"genre1", "genre2"}),
}.XESAMGenre()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedGenre, genre, "unexpected genre")
//not present
expectedGenre = nil
expectedErrorText = "<nil>"
genre, err = Metadata{}.XESAMGenre()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedGenre, genre, "unexpected genre")
//unexpected type
expectedGenre = nil
expectedErrorText = "int could not be parsed to []string: the given type is not as expected"
genre, err = Metadata{
"xesam:genre": dbus.MakeVariant(42),
}.XESAMGenre()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedGenre, genre, "unexpected genre")
}
func TestMetadata_XESAMLastUsed(t *testing.T) {
var expectedLastUsed time.Time
var expectedErrorText string
var lastUsed time.Time
var err error
//happycase
expectedLastUsed = time.Date(2007, 4, 29, 13, 56, 0, 0, time.FixedZone("", 0))
expectedErrorText = "<nil>"
lastUsed, err = Metadata{
"xesam:lastUsed": dbus.MakeVariant("2007-04-29T13:56+00:00"),
}.XESAMLastUsed()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedLastUsed.Equal(lastUsed), "unexpected lastUsed", expectedLastUsed, lastUsed)
//not present
expectedLastUsed = time.Time{}
expectedErrorText = "<nil>"
lastUsed, err = Metadata{}.XESAMLastUsed()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedLastUsed.Equal(lastUsed), "unexpected lastUsed", expectedLastUsed, lastUsed)
//unexpected type
expectedLastUsed = time.Time{}
expectedErrorText = "int could not be parsed to string: the given type is not as expected"
lastUsed, err = Metadata{
"xesam:lastUsed": dbus.MakeVariant(42),
}.XESAMLastUsed()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedLastUsed.Equal(lastUsed), "unexpected lastUsed", expectedLastUsed, lastUsed)
//unexpected date format
expectedLastUsed = time.Time{}
expectedErrorText = `cound not parse time: parsing time "not a date-time" as "2006-01-02T15:04-07:00": cannot parse "not a date-time" as "2006": the given type is not as expected`
lastUsed, err = Metadata{
"xesam:lastUsed": dbus.MakeVariant("not a date-time"),
}.XESAMLastUsed()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.True(t, expectedLastUsed.Equal(lastUsed), "unexpected lastUsed", expectedLastUsed, lastUsed)
}
func TestMetadata_XESAMLyricist(t *testing.T) {
var expectedLyricist []string
var expectedErrorText string
var lyricist []string
var err error
//happycase
expectedLyricist = []string{"genre1", "genre2"}
expectedErrorText = "<nil>"
lyricist, err = Metadata{
"xesam:lyricist": dbus.MakeVariant([]string{"genre1", "genre2"}),
}.XESAMLyricist()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedLyricist, lyricist, "unexpected lyricist")
//not present
expectedLyricist = nil
expectedErrorText = "<nil>"
lyricist, err = Metadata{}.XESAMLyricist()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedLyricist, lyricist, "unexpected lyricist")
//unexpected type
expectedLyricist = nil
expectedErrorText = "int could not be parsed to []string: the given type is not as expected"
lyricist, err = Metadata{
"xesam:lyricist": dbus.MakeVariant(42),
}.XESAMLyricist()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedLyricist, lyricist, "unexpected lyricist")
}
func TestMetadata_XESAMTitle(t *testing.T) {
var expectedTitle string
var expectedErrorText string
var title string
var err error
//happycase
expectedTitle = "title"
expectedErrorText = "<nil>"
title, err = Metadata{
"xesam:title": dbus.MakeVariant("title"),
}.XESAMTitle()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedTitle, title, "unexpected title")
//not present
expectedTitle = ""
expectedErrorText = "<nil>"
title, err = Metadata{}.XESAMTitle()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedTitle, title, "unexpected title")
//unexpected type
expectedTitle = ""
expectedErrorText = "int could not be parsed to string: the given type is not as expected"
title, err = Metadata{
"xesam:title": dbus.MakeVariant(42),
}.XESAMTitle()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedTitle, title, "unexpected title")
}
func TestMetadata_XESAMTrackNumber(t *testing.T) {
var expectedTrackNumber int
var expectedErrorText string
var trackNumber int
var err error
//happycase
expectedTrackNumber = 42
expectedErrorText = "<nil>"
trackNumber, err = Metadata{
"xesam:trackNumber": dbus.MakeVariant(42),
}.XESAMTrackNumber()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedTrackNumber, trackNumber, "unexpected trackNumber")
//not present
expectedTrackNumber = 0
expectedErrorText = "<nil>"
trackNumber, err = Metadata{}.XESAMTrackNumber()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedTrackNumber, trackNumber, "unexpected trackNumber")
//unexpected type
expectedTrackNumber = 0
expectedErrorText = "string could not be parsed to int: the given type is not as expected"
trackNumber, err = Metadata{
"xesam:trackNumber": dbus.MakeVariant("string"),
}.XESAMTrackNumber()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedTrackNumber, trackNumber, "unexpected trackNumber")
}
func TestMetadata_XESAMURL(t *testing.T) {
var expectedURL string
var expectedErrorText string
var url string
var err error
//happycase
expectedURL = "url"
expectedErrorText = "<nil>"
url, err = Metadata{
"xesam:url": dbus.MakeVariant("url"),
}.XESAMURL()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedURL, url, "unexpected url")
//not present
expectedURL = ""
expectedErrorText = "<nil>"
url, err = Metadata{}.XESAMURL()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedURL, url, "unexpected url")
//unexpected type
expectedURL = ""
expectedErrorText = "int could not be parsed to string: the given type is not as expected"
url, err = Metadata{
"xesam:url": dbus.MakeVariant(42),
}.XESAMURL()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedURL, url, "unexpected url")
}
func TestMetadata_XESAMUseCount(t *testing.T) {
var expectedUseCount int
var expectedErrorText string
var useCount int
var err error
//happycase
expectedUseCount = 42
expectedErrorText = "<nil>"
useCount, err = Metadata{
"xesam:useCount": dbus.MakeVariant(42),
}.XESAMUseCount()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedUseCount, useCount, "unexpected useCount")
//not present
expectedUseCount = 0
expectedErrorText = "<nil>"
useCount, err = Metadata{}.XESAMUseCount()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedUseCount, useCount, "unexpected useCount")
//unexpected type
expectedUseCount = 0
expectedErrorText = "string could not be parsed to int: the given type is not as expected"
useCount, err = Metadata{
"xesam:useCount": dbus.MakeVariant("string"),
}.XESAMUseCount()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedUseCount, useCount, "unexpected useCount")
}
func TestMetadata_XESAMUserRating(t *testing.T) {
var expectedUserRating float64
var expectedErrorText string
var userRating float64
var err error
//happycase
expectedUserRating = 4711
expectedErrorText = "<nil>"
userRating, err = Metadata{
"xesam:userRating": dbus.MakeVariant(float64(4711)),
}.XESAMUserRating()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedUserRating, userRating, "unexpected userRating")
//not present
expectedUserRating = 0
expectedErrorText = "<nil>"
userRating, err = Metadata{}.XESAMUserRating()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedUserRating, userRating, "unexpected userRating")
//unexpected type
expectedUserRating = 0
expectedErrorText = "string could not be parsed to float64: the given type is not as expected"
userRating, err = Metadata{
"xesam:userRating": dbus.MakeVariant("string"),
}.XESAMUserRating()
assert.Equal(t, expectedErrorText, fmt.Sprint(err), "unexpected error text")
assert.Equal(t, expectedUserRating, userRating, "unexpected userRating")
}
func TestMetadata_Find(t *testing.T) {
expectedValue := dbus.MakeVariant("123456")
value, found := Metadata{
"myKey": dbus.MakeVariant("123456"),
}.Find("myKey")
assert.True(t, found)
assert.Equal(t, expectedValue, value)
}