mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
paginate artist album fetching for deezer and qobuz
This commit is contained in:
@@ -157,6 +157,53 @@ func TestGetLabelPagination(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetArtistPagination(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
offset := r.URL.Query().Get("offset")
|
||||
if offset == "" {
|
||||
offset = "0"
|
||||
}
|
||||
|
||||
resp := map[string]any{}
|
||||
switch offset {
|
||||
case "0":
|
||||
resp = map[string]any{
|
||||
"albums_count": 620,
|
||||
"albums": map[string]any{"items": makeItems(0, 500)},
|
||||
}
|
||||
case "500":
|
||||
resp = map[string]any{"albums": map[string]any{"items": makeItems(500, 620)}}
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"message": "not found"})
|
||||
return
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(resp)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
c := newTestClient(t)
|
||||
c.loggedIn = true
|
||||
c.baseURL = ts.URL
|
||||
|
||||
raw, err := c.GetMetadata(context.Background(), "artist-id", "artist")
|
||||
if err != nil {
|
||||
t.Fatalf("GetMetadata() error = %v", err)
|
||||
}
|
||||
albums, ok := mapValue(raw["albums"])
|
||||
if !ok {
|
||||
t.Fatalf("albums missing")
|
||||
}
|
||||
items, ok := albums["items"].([]any)
|
||||
if !ok {
|
||||
t.Fatalf("items missing")
|
||||
}
|
||||
if len(items) != 620 {
|
||||
t.Fatalf("len(items) = %d, want 620", len(items))
|
||||
}
|
||||
}
|
||||
|
||||
func newTestClient(t *testing.T) *Client {
|
||||
t.Helper()
|
||||
d := config.DefaultConfigData()
|
||||
|
||||
Reference in New Issue
Block a user