Something went wrong. Try again.
Self-hosted web interface and downloader for Qobuz.
downloader self-hosted music qobuz
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155package api_test
import ( "encoding/json" "testing"
"gobuz/internal/api")
func TestID_UnmarshalJSON(t *testing.T) { tests := []struct { name string in string want api.ID }{ {name: "string ID", in: `"abc123"`, want: "abc123"}, {name: "integer ID", in: `12345`, want: "12345"}, {name: "null ID", in: `null`, want: ""}, {name: "empty string", in: `""`, want: ""}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var id api.ID if err := json.Unmarshal([]byte(tt.in), &id); err != nil { t.Fatalf("unexpected unmarshal error: %v", err) } if id != tt.want { t.Errorf("got %q, want %q", id, tt.want) } if id.String() != string(tt.want) { t.Errorf("String() = %q, want %q", id.String(), string(tt.want)) } }) }}
func TestImage_BestAndSmallest(t *testing.T) { imgAll := api.Image{ Small: "https://example.com/small.jpg", Thumbnail: "https://example.com/thumb.jpg", Large: "https://example.com/large.jpg", ExtraLarge: "https://example.com/xlarge.jpg", Mega: "https://example.com/mega.jpg", }
if got := imgAll.Best(); got != "https://example.com/mega.jpg" { t.Errorf("imgAll.Best() = %q, want mega", got) } if got := imgAll.Smallest(); got != "https://example.com/small.jpg" { t.Errorf("imgAll.Smallest() = %q, want small", got) }
imgPartial := api.Image{ Thumbnail: "https://example.com/thumb.jpg", ExtraLarge: "https://example.com/xlarge.jpg", } if got := imgPartial.Best(); got != "https://example.com/xlarge.jpg" { t.Errorf("imgPartial.Best() = %q, want xlarge", got) } if got := imgPartial.Smallest(); got != "https://example.com/thumb.jpg" { t.Errorf("imgPartial.Smallest() = %q, want thumb", got) }
var imgEmpty api.Image if got := imgEmpty.Best(); got != "" { t.Errorf("imgEmpty.Best() = %q, want empty", got) } if got := imgEmpty.Smallest(); got != "" { t.Errorf("imgEmpty.Smallest() = %q, want empty", got) }}
func TestQuality_Methods(t *testing.T) { tests := []struct { q api.Quality wantID int wantLbl string valid bool }{ {api.QualityMp3, 5, "MP3 320kbps", true}, {api.QualityLossless, 6, "FLAC 16-bit/44.1kHz", true}, {api.QualityHiRes, 7, "FLAC 24-bit/≤96kHz", true}, {api.QualityUltraHiRes, 27, "FLAC 24-bit/>96kHz", true}, {api.Quality(99), 99, "Unknown", false}, }
for _, tt := range tests { if tt.q.ID() != tt.wantID { t.Errorf("Quality(%d).ID() = %d, want %d", tt.q, tt.q.ID(), tt.wantID) } if tt.q.Label() != tt.wantLbl { t.Errorf("Quality(%d).Label() = %q, want %q", tt.q, tt.q.Label(), tt.wantLbl) } if tt.q.IsValid() != tt.valid { t.Errorf("Quality(%d).IsValid() = %v, want %v", tt.q, tt.q.IsValid(), tt.valid) } }}
func TestAlbumAward_UnmarshalJSON(t *testing.T) { tests := []struct { name string raw string wantID api.ID wantAwardID api.ID wantName string wantAwardedAt api.ID }{ { name: "numeric awarded_at and string award_id", raw: `{"name":"Pitchfork: Best New Music","awarded_at":1506808800,"award_id":"74"}`, wantAwardID: "74", wantName: "Pitchfork: Best New Music", wantAwardedAt: "1506808800", }, { name: "string date awarded_at and numeric id", raw: `{"id":74,"name":"Pitchfork: Best New Music","awarded_at":"2017-10-01"}`, wantID: "74", wantName: "Pitchfork: Best New Music", wantAwardedAt: "2017-10-01", }, { name: "camelCase awardId and awardedAt", raw: `{"awardId":74,"name":"Pitchfork: Best New Music","awardedAt":1506808800}`, wantID: "74", wantAwardID: "74", wantName: "Pitchfork: Best New Music", wantAwardedAt: "1506808800", }, }
for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var award api.AlbumAward if err := json.Unmarshal([]byte(tt.raw), &award); err != nil { t.Fatalf("unexpected unmarshal error: %v", err) } if award.Name != tt.wantName { t.Errorf("award.Name = %q, want %q", award.Name, tt.wantName) } if award.AwardedAt != tt.wantAwardedAt { t.Errorf("award.AwardedAt = %q, want %q", award.AwardedAt, tt.wantAwardedAt) } if tt.wantID != "" && award.ID != tt.wantID { t.Errorf("award.ID = %q, want %q", award.ID, tt.wantID) } if tt.wantAwardID != "" && award.AwardID != tt.wantAwardID { t.Errorf("award.AwardID = %q, want %q", award.AwardID, tt.wantAwardID) } }) }}