-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathretrieval_test.go
64 lines (58 loc) · 1.38 KB
/
retrieval_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
package subsonic
import (
"image"
"testing"
)
func runRetrievalTests(client Client, t *testing.T) {
sampleSong := getSampleSong(client)
t.Run("Stream", func(t *testing.T) {
// Purposefully choose an ID that returns an error
_, err := client.Stream("1", nil)
if err == nil {
t.Error("An error was not returned on ID 1")
}
contents, err := client.Stream(sampleSong.ID, nil)
if err != nil {
t.Error(err)
}
if contents == nil {
t.Error("No content returned")
}
sample := make([]byte, 8)
_, err = contents.Read(sample)
if err != nil {
t.Errorf("Error reading sample %v: %v", sample, err)
}
})
t.Run("Download", func(t *testing.T) {
contents, err := client.Download(sampleSong.ID)
if err != nil {
t.Fatal(err)
}
if contents == nil {
t.Fatal("No content returned")
}
sample := make([]byte, 8)
_, err = contents.Read(sample)
if err != nil {
t.Errorf("Error reading sample %v: %v", sample, err)
}
})
t.Run("GetCoverArt", func(t *testing.T) {
img, err := client.GetCoverArt(sampleSong.ID, nil)
if err != nil {
t.Fatal(err)
}
var empty image.Rectangle
if img.Bounds() == empty {
t.Fatalf("Image %#v has empty bounds", img)
}
})
t.Run("GetAvatar", func(t *testing.T) {
// Avatars aren't always returned by servers, so this test is a no-op
_, err := client.GetAvatar(client.User)
if err != nil {
t.Log(err)
}
})
}