test(coverart, subsonic, server): merge repeated cases into tables (#8298)
release / web (push) Successful in 1m35s
release / go (push) Successful in 1m58s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m0s
release / android (push) Successful in 4m26s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 5m8s
release / web (push) Successful in 1m35s
release / go (push) Successful in 1m58s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m0s
release / android (push) Successful in 4m26s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 5m8s
- coverart: the four providers' identity and default tests, Last.fm's five not-found-without-asking tests, the four "which artists are asked again" database tests (now one reset over four artists), and the thumbnail-only and fanart-only tests. - subsonic: getUser's six tests and decodePassword's three, one table each. Dropped TestTokenMD5Derivation: it checked crypto/md5 against a constant and called no Minstrel code. - server: the four web-app-versus-API path tests start one server, not four. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package coverart
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -45,256 +46,115 @@ func insertArtist(t *testing.T, q *dbq.Queries, ctx context.Context, name, mbid
|
||||
return a.ID
|
||||
}
|
||||
|
||||
// --- Eligibility tests ---
|
||||
|
||||
func TestEnrichArtist_NullSource_Eligible(t *testing.T) {
|
||||
// An artist is asked about when it has no art source yet, or when it was
|
||||
// settled as "none" under an older set of providers (the version counts
|
||||
// provider changes). One with art, or settled "none" under the current
|
||||
// providers, is left alone, and no file is written for it.
|
||||
func TestEnrichArtist_WhichArtistsAreAsked(t *testing.T) {
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
|
||||
resetRegistryForTests()
|
||||
t.Cleanup(resetRegistryForTests)
|
||||
|
||||
stub := &stubArtistProvider{
|
||||
Register(&stubArtistProvider{
|
||||
fakeProvider: fakeProvider{id: "stub-artist", defaultOn: true},
|
||||
thumb: []byte("thumb_bytes"),
|
||||
fanart: []byte("fanart_bytes"),
|
||||
}
|
||||
Register(stub)
|
||||
|
||||
})
|
||||
e := newTestEnricher(t, pool)
|
||||
artistID := insertArtist(t, q, ctx, "Null Artist", "11111111-1111-1111-1111-111111111111")
|
||||
|
||||
current := e.settings.CurrentVersion()
|
||||
dataDir := t.TempDir()
|
||||
if err := e.EnrichArtist(ctx, artistID, dataDir); err != nil {
|
||||
t.Fatalf("EnrichArtist: %v", err)
|
||||
}
|
||||
|
||||
row, err := q.GetArtistByID(ctx, artistID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetArtistByID: %v", err)
|
||||
}
|
||||
if row.ArtistArtSource == nil || *row.ArtistArtSource != "stub-artist" {
|
||||
t.Errorf("source = %v, want 'stub-artist'", row.ArtistArtSource)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnrichArtist_FoundSource_Skip(t *testing.T) {
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
|
||||
resetRegistryForTests()
|
||||
t.Cleanup(resetRegistryForTests)
|
||||
|
||||
stub := &stubArtistProvider{
|
||||
fakeProvider: fakeProvider{id: "stub-artist", defaultOn: true},
|
||||
thumb: []byte("should_not_write"),
|
||||
}
|
||||
Register(stub)
|
||||
|
||||
e := newTestEnricher(t, pool)
|
||||
artistID := insertArtist(t, q, ctx, "Found Artist", "22222222-2222-2222-2222-222222222222")
|
||||
|
||||
// Pre-mark with a "found" source.
|
||||
src := "theaudiodb"
|
||||
if err := q.SetArtistArtWithVersion(ctx, dbq.SetArtistArtWithVersionParams{
|
||||
ID: artistID,
|
||||
ArtistArtSource: &src,
|
||||
ArtistArtSourcesVersion: e.settings.CurrentVersion(),
|
||||
}); err != nil {
|
||||
t.Fatalf("set: %v", err)
|
||||
}
|
||||
|
||||
dataDir := t.TempDir()
|
||||
if err := e.EnrichArtist(ctx, artistID, dataDir); err != nil {
|
||||
t.Fatalf("EnrichArtist: %v", err)
|
||||
}
|
||||
|
||||
// Source must remain 'theaudiodb'; no files should have been written.
|
||||
row, err := q.GetArtistByID(ctx, artistID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetArtistByID: %v", err)
|
||||
}
|
||||
if row.ArtistArtSource == nil || *row.ArtistArtSource != "theaudiodb" {
|
||||
t.Errorf("source = %v, want 'theaudiodb' (preserved)", row.ArtistArtSource)
|
||||
}
|
||||
thumbPath := filepath.Join(dataDir, "artist-art", uuidString(artistID), "thumb.jpg")
|
||||
if _, err := os.Stat(thumbPath); !os.IsNotExist(err) {
|
||||
t.Errorf("expected no thumb.jpg (skip), got stat err = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnrichArtist_NoneCurrentVersion_Skip(t *testing.T) {
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
|
||||
resetRegistryForTests()
|
||||
t.Cleanup(resetRegistryForTests)
|
||||
|
||||
stub := &stubArtistProvider{
|
||||
fakeProvider: fakeProvider{id: "stub-artist", defaultOn: true},
|
||||
thumb: []byte("should_not_write"),
|
||||
}
|
||||
Register(stub)
|
||||
|
||||
e := newTestEnricher(t, pool)
|
||||
artistID := insertArtist(t, q, ctx, "None Current Artist", "33333333-3333-3333-3333-333333333333")
|
||||
|
||||
src := "none"
|
||||
if err := q.SetArtistArtWithVersion(ctx, dbq.SetArtistArtWithVersionParams{
|
||||
ID: artistID,
|
||||
ArtistArtSource: &src,
|
||||
ArtistArtSourcesVersion: e.settings.CurrentVersion(),
|
||||
}); err != nil {
|
||||
t.Fatalf("set: %v", err)
|
||||
}
|
||||
|
||||
dataDir := t.TempDir()
|
||||
if err := e.EnrichArtist(ctx, artistID, dataDir); err != nil {
|
||||
t.Fatalf("EnrichArtist: %v", err)
|
||||
}
|
||||
|
||||
// Source must remain 'none' at current version.
|
||||
row, err := q.GetArtistByID(ctx, artistID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetArtistByID: %v", err)
|
||||
}
|
||||
if row.ArtistArtSource == nil || *row.ArtistArtSource != "none" {
|
||||
t.Errorf("source = %v, want 'none' (skip — current version)", row.ArtistArtSource)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnrichArtist_NoneStaleVersion_FlipAndRetry(t *testing.T) {
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
|
||||
resetRegistryForTests()
|
||||
t.Cleanup(resetRegistryForTests)
|
||||
|
||||
stub := &stubArtistProvider{
|
||||
fakeProvider: fakeProvider{id: "stub-artist", defaultOn: true},
|
||||
thumb: []byte("retry_thumb"),
|
||||
fanart: []byte("retry_fanart"),
|
||||
}
|
||||
Register(stub)
|
||||
|
||||
e := newTestEnricher(t, pool)
|
||||
artistID := insertArtist(t, q, ctx, "Stale None Artist", "44444444-4444-4444-4444-444444444444")
|
||||
|
||||
// Set 'none' with a stale version (currentVersion - 1).
|
||||
staleVersion := e.settings.CurrentVersion() - 1
|
||||
src := "none"
|
||||
if err := q.SetArtistArtWithVersion(ctx, dbq.SetArtistArtWithVersionParams{
|
||||
ID: artistID,
|
||||
ArtistArtSource: &src,
|
||||
ArtistArtSourcesVersion: staleVersion,
|
||||
}); err != nil {
|
||||
t.Fatalf("set stale none: %v", err)
|
||||
}
|
||||
|
||||
dataDir := t.TempDir()
|
||||
if err := e.EnrichArtist(ctx, artistID, dataDir); err != nil {
|
||||
t.Fatalf("EnrichArtist: %v", err)
|
||||
}
|
||||
|
||||
row, err := q.GetArtistByID(ctx, artistID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetArtistByID: %v", err)
|
||||
}
|
||||
// Stale 'none' should be flipped and re-enriched; stub succeeds so
|
||||
// source becomes the provider ID.
|
||||
if row.ArtistArtSource == nil || *row.ArtistArtSource != "stub-artist" {
|
||||
t.Errorf("source = %v, want 'stub-artist' (stale none flipped and retried)", row.ArtistArtSource)
|
||||
}
|
||||
}
|
||||
|
||||
// --- Atomicity: thumb-only / fanart-only ---
|
||||
|
||||
func TestEnrichArtist_ThumbOnly_ThumbPathSetFanartNull(t *testing.T) {
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
|
||||
resetRegistryForTests()
|
||||
t.Cleanup(resetRegistryForTests)
|
||||
|
||||
stub := &stubArtistProvider{
|
||||
fakeProvider: fakeProvider{id: "thumb-only-provider", defaultOn: true},
|
||||
thumb: []byte("thumb_only"),
|
||||
fanart: nil,
|
||||
}
|
||||
Register(stub)
|
||||
|
||||
e := newTestEnricher(t, pool)
|
||||
artistID := insertArtist(t, q, ctx, "Thumb Only Artist", "55555555-5555-5555-5555-555555555555")
|
||||
|
||||
dataDir := t.TempDir()
|
||||
if err := e.EnrichArtist(ctx, artistID, dataDir); err != nil {
|
||||
t.Fatalf("EnrichArtist: %v", err)
|
||||
}
|
||||
|
||||
row, err := q.GetArtistByID(ctx, artistID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetArtistByID: %v", err)
|
||||
}
|
||||
if row.ArtistArtSource == nil || *row.ArtistArtSource != "thumb-only-provider" {
|
||||
t.Errorf("source = %v, want 'thumb-only-provider'", row.ArtistArtSource)
|
||||
}
|
||||
if row.ArtistThumbPath == nil {
|
||||
t.Errorf("artist_thumb_path is nil, want a path")
|
||||
}
|
||||
if row.ArtistFanartPath != nil {
|
||||
t.Errorf("artist_fanart_path = %v, want nil (fanart not provided)", row.ArtistFanartPath)
|
||||
}
|
||||
if row.ArtistThumbPath != nil {
|
||||
body, rerr := os.ReadFile(*row.ArtistThumbPath)
|
||||
if rerr != nil {
|
||||
t.Fatalf("read thumb: %v", rerr)
|
||||
for i, tc := range []struct {
|
||||
name string
|
||||
source string // "" leaves it NULL
|
||||
version int32
|
||||
wantSource string
|
||||
wantAsked bool
|
||||
}{
|
||||
{"no source yet", "", 0, "stub-artist", true},
|
||||
{"art already found", "theaudiodb", current, "theaudiodb", false},
|
||||
{"none under the current providers", "none", current, "none", false},
|
||||
{"none under older providers", "none", current - 1, "stub-artist", true},
|
||||
} {
|
||||
artistID := insertArtist(t, q, ctx, tc.name, fmt.Sprintf("0000000%d-1111-1111-1111-111111111111", i))
|
||||
if tc.source != "" {
|
||||
src := tc.source
|
||||
if err := q.SetArtistArtWithVersion(ctx, dbq.SetArtistArtWithVersionParams{
|
||||
ID: artistID, ArtistArtSource: &src, ArtistArtSourcesVersion: tc.version,
|
||||
}); err != nil {
|
||||
t.Fatalf("%s: set: %v", tc.name, err)
|
||||
}
|
||||
}
|
||||
if string(body) != "thumb_only" {
|
||||
t.Errorf("thumb content = %q, want 'thumb_only'", string(body))
|
||||
if err := e.EnrichArtist(ctx, artistID, dataDir); err != nil {
|
||||
t.Fatalf("%s: EnrichArtist: %v", tc.name, err)
|
||||
}
|
||||
row, err := q.GetArtistByID(ctx, artistID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if row.ArtistArtSource == nil || *row.ArtistArtSource != tc.wantSource {
|
||||
t.Errorf("%s: source = %v, want %q", tc.name, row.ArtistArtSource, tc.wantSource)
|
||||
}
|
||||
_, statErr := os.Stat(filepath.Join(dataDir, "artist-art", uuidString(artistID), "thumb.jpg"))
|
||||
if asked := statErr == nil; asked != tc.wantAsked {
|
||||
t.Errorf("%s: thumb written = %v, want %v", tc.name, asked, tc.wantAsked)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnrichArtist_FanartOnly_FanartPathSetThumbNull(t *testing.T) {
|
||||
// A provider with only one of the two pictures still settles the artist as
|
||||
// found: the picture it has is written and its path set, and the other path
|
||||
// stays NULL so the clients fall back rather than load a missing file.
|
||||
func TestEnrichArtist_OnePictureOfTwo(t *testing.T) {
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
|
||||
resetRegistryForTests()
|
||||
t.Cleanup(resetRegistryForTests)
|
||||
|
||||
stub := &stubArtistProvider{
|
||||
fakeProvider: fakeProvider{id: "fanart-only-provider", defaultOn: true},
|
||||
thumb: nil,
|
||||
fanart: []byte("fanart_only"),
|
||||
}
|
||||
stub := &stubArtistProvider{fakeProvider: fakeProvider{id: "one-picture", defaultOn: true}}
|
||||
Register(stub)
|
||||
|
||||
e := newTestEnricher(t, pool)
|
||||
artistID := insertArtist(t, q, ctx, "Fanart Only Artist", "66666666-6666-6666-6666-666666666666")
|
||||
|
||||
dataDir := t.TempDir()
|
||||
if err := e.EnrichArtist(ctx, artistID, dataDir); err != nil {
|
||||
t.Fatalf("EnrichArtist: %v", err)
|
||||
}
|
||||
|
||||
row, err := q.GetArtistByID(ctx, artistID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetArtistByID: %v", err)
|
||||
}
|
||||
if row.ArtistArtSource == nil || *row.ArtistArtSource != "fanart-only-provider" {
|
||||
t.Errorf("source = %v, want 'fanart-only-provider'", row.ArtistArtSource)
|
||||
}
|
||||
if row.ArtistThumbPath != nil {
|
||||
t.Errorf("artist_thumb_path = %v, want nil (thumb not provided)", row.ArtistThumbPath)
|
||||
}
|
||||
if row.ArtistFanartPath == nil {
|
||||
t.Errorf("artist_fanart_path is nil, want a path")
|
||||
for i, tc := range []struct {
|
||||
name string
|
||||
thumb, fanart []byte
|
||||
}{
|
||||
{"a thumbnail only", []byte("thumb_only"), nil},
|
||||
{"fanart only", nil, []byte("fanart_only")},
|
||||
} {
|
||||
stub.thumb, stub.fanart = tc.thumb, tc.fanart
|
||||
artistID := insertArtist(t, q, ctx, tc.name, fmt.Sprintf("5555555%d-5555-5555-5555-555555555555", i))
|
||||
if err := e.EnrichArtist(ctx, artistID, dataDir); err != nil {
|
||||
t.Fatalf("%s: EnrichArtist: %v", tc.name, err)
|
||||
}
|
||||
row, err := q.GetArtistByID(ctx, artistID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if row.ArtistArtSource == nil || *row.ArtistArtSource != "one-picture" {
|
||||
t.Errorf("%s: source = %v, want one-picture", tc.name, row.ArtistArtSource)
|
||||
}
|
||||
for _, pic := range []struct {
|
||||
kind string
|
||||
path *string
|
||||
want []byte
|
||||
}{{"thumbnail", row.ArtistThumbPath, tc.thumb}, {"fanart", row.ArtistFanartPath, tc.fanart}} {
|
||||
if pic.want == nil {
|
||||
if pic.path != nil {
|
||||
t.Errorf("%s: %s path = %q, want NULL", tc.name, pic.kind, *pic.path)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if pic.path == nil {
|
||||
t.Errorf("%s: %s path is NULL", tc.name, pic.kind)
|
||||
continue
|
||||
}
|
||||
if body, err := os.ReadFile(*pic.path); err != nil || string(body) != string(pic.want) {
|
||||
t.Errorf("%s: %s file = %q, %v; want %q", tc.name, pic.kind, body, err, pic.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,19 +25,6 @@ func newDeezerTestProvider(t *testing.T, baseURL string) *deezerProvider {
|
||||
return p
|
||||
}
|
||||
|
||||
func TestDeezer_ID(t *testing.T) {
|
||||
p := &deezerProvider{}
|
||||
if p.ID() != "deezer" {
|
||||
t.Errorf("ID = %q, want deezer", p.ID())
|
||||
}
|
||||
if p.RequiresAPIKey() {
|
||||
t.Error("RequiresAPIKey = true, want false")
|
||||
}
|
||||
if !p.DefaultEnabled() {
|
||||
t.Error("DefaultEnabled = false, want true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeezer_FetchArtistArt_Success(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
srv := httptest.NewServer(mux)
|
||||
|
||||
@@ -29,19 +29,6 @@ func newLastfmTestProvider(t *testing.T, baseURL, key string) *lastfmProvider {
|
||||
|
||||
// ── Identity / metadata ──────────────────────────────────────────────────────
|
||||
|
||||
func TestLastfm_ID(t *testing.T) {
|
||||
p := &lastfmProvider{}
|
||||
if p.ID() != "lastfm" {
|
||||
t.Errorf("ID = %q, want lastfm", p.ID())
|
||||
}
|
||||
if !p.RequiresAPIKey() {
|
||||
t.Error("RequiresAPIKey = false, want true")
|
||||
}
|
||||
if p.DefaultEnabled() {
|
||||
t.Error("DefaultEnabled = true, want false")
|
||||
}
|
||||
}
|
||||
|
||||
// ── FetchArtistArt — happy paths ─────────────────────────────────────────────
|
||||
|
||||
func TestLastfm_FetchArtistArt_ByMBID(t *testing.T) {
|
||||
@@ -131,23 +118,6 @@ func TestLastfm_FetchArtistArt_PlaceholderImage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastfm_FetchArtistArt_AlbumPlaceholderImage(t *testing.T) {
|
||||
// Second known placeholder hash (album cover default).
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"artist":{"name":"Y","image":[
|
||||
{"#text":"https://lastfm.freetls.fastly.net/i/u/300x300/c6f59c1e5e7240a4c0d427abd71f3dbb.jpg","size":"extralarge"}
|
||||
]}}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
p := newLastfmTestProvider(t, srv.URL+"/", "test-key")
|
||||
_, _, err := p.FetchArtistArt(context.Background(), ArtistRef{Name: "Y"})
|
||||
if !errors.Is(err, ErrNotFound) {
|
||||
t.Errorf("err = %v, want ErrNotFound for album placeholder hash", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastfm_FetchArtistArt_EmptyImageArray(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -177,42 +147,31 @@ func TestLastfm_FetchArtistArt_ErrorResponse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastfm_FetchArtistArt_EmptyAPIKey(t *testing.T) {
|
||||
// Enabled but no key: every call must return ErrNotFound, not a network error.
|
||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
||||
p.enabled.Store(true)
|
||||
emptyKey := ""
|
||||
p.apiKey.Store(&emptyKey)
|
||||
|
||||
_, _, err := p.FetchArtistArt(context.Background(), ArtistRef{Name: "X"})
|
||||
if !errors.Is(err, ErrNotFound) {
|
||||
t.Errorf("err = %v, want ErrNotFound when API key is empty", err)
|
||||
// Last.fm answers "not found" without a request when it is switched off, has
|
||||
// no key, or is given nothing to look up, rather than failing on the network.
|
||||
func TestLastfm_AnswersNotFoundWithoutAsking(t *testing.T) {
|
||||
provider := func(enabled bool, key string) *lastfmProvider {
|
||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm",
|
||||
HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
||||
p.enabled.Store(enabled)
|
||||
p.apiKey.Store(&key)
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastfm_FetchArtistArt_Disabled(t *testing.T) {
|
||||
// Key set but disabled.
|
||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
||||
// enabled defaults to false
|
||||
key := "some-key"
|
||||
p.apiKey.Store(&key)
|
||||
|
||||
_, _, err := p.FetchArtistArt(context.Background(), ArtistRef{Name: "X"})
|
||||
if !errors.Is(err, ErrNotFound) {
|
||||
t.Errorf("err = %v, want ErrNotFound when disabled", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastfm_FetchArtistArt_EmptyRefs(t *testing.T) {
|
||||
// Neither MBID nor Name: ErrNotFound without making any HTTP call.
|
||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
||||
p.enabled.Store(true)
|
||||
key := "test-key"
|
||||
p.apiKey.Store(&key)
|
||||
|
||||
_, _, err := p.FetchArtistArt(context.Background(), ArtistRef{})
|
||||
if !errors.Is(err, ErrNotFound) {
|
||||
t.Errorf("err = %v, want ErrNotFound for empty ArtistRef", err)
|
||||
ctx := context.Background()
|
||||
album := AlbumRef{ArtistName: "X", AlbumTitle: "Y"}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
call func() error
|
||||
}{
|
||||
{"artist art with no key", func() error { _, _, err := provider(true, "").FetchArtistArt(ctx, ArtistRef{Name: "X"}); return err }},
|
||||
{"artist art while off", func() error { _, _, err := provider(false, "k").FetchArtistArt(ctx, ArtistRef{Name: "X"}); return err }},
|
||||
{"artist art with no name or MBID", func() error { _, _, err := provider(true, "k").FetchArtistArt(ctx, ArtistRef{}); return err }},
|
||||
{"album cover with no key", func() error { _, err := provider(true, "").FetchAlbumCover(ctx, album); return err }},
|
||||
{"album cover while off", func() error { _, err := provider(false, "k").FetchAlbumCover(ctx, album); return err }},
|
||||
} {
|
||||
if err := tc.call(); !errors.Is(err, ErrNotFound) {
|
||||
t.Errorf("%s: err = %v, want ErrNotFound", tc.name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,30 +280,6 @@ func TestLastfm_FetchAlbumCover_MissingFields(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastfm_FetchAlbumCover_EmptyAPIKey(t *testing.T) {
|
||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
||||
p.enabled.Store(true)
|
||||
emptyKey := ""
|
||||
p.apiKey.Store(&emptyKey)
|
||||
|
||||
_, err := p.FetchAlbumCover(context.Background(), AlbumRef{ArtistName: "X", AlbumTitle: "Y"})
|
||||
if !errors.Is(err, ErrNotFound) {
|
||||
t.Errorf("err = %v, want ErrNotFound when API key is empty", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastfm_FetchAlbumCover_Disabled(t *testing.T) {
|
||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
||||
// enabled defaults to false
|
||||
key := "some-key"
|
||||
p.apiKey.Store(&key)
|
||||
|
||||
_, err := p.FetchAlbumCover(context.Background(), AlbumRef{ArtistName: "X", AlbumTitle: "Y"})
|
||||
if !errors.Is(err, ErrNotFound) {
|
||||
t.Errorf("err = %v, want ErrNotFound when disabled", err)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Rate-limit serialization ─────────────────────────────────────────────────
|
||||
|
||||
// lastfmTestPeriod is providers.LastfmPacer's spacing.
|
||||
|
||||
@@ -28,24 +28,6 @@ func newMBCAAProviderForTest(t *testing.T, mockURL string) *mbcaaProvider {
|
||||
return p
|
||||
}
|
||||
|
||||
func TestMBCAAProvider_ID(t *testing.T) {
|
||||
resetRegistryForTests()
|
||||
defer resetRegistryForTests()
|
||||
p := newMBCAAProvider(FetcherConfig{})
|
||||
if p.ID() != "mbcaa" {
|
||||
t.Errorf("ID = %q, want mbcaa", p.ID())
|
||||
}
|
||||
if p.DisplayName() != "Cover Art Archive" {
|
||||
t.Errorf("DisplayName = %q, want Cover Art Archive", p.DisplayName())
|
||||
}
|
||||
if p.RequiresAPIKey() {
|
||||
t.Error("RequiresAPIKey = true, want false")
|
||||
}
|
||||
if !p.DefaultEnabled() {
|
||||
t.Error("DefaultEnabled = false, want true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMBCAAProvider_FetchAlbumCover_Success(t *testing.T) {
|
||||
imageBody := []byte("FAKE_JPEG")
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -114,3 +114,26 @@ func TestCapabilityFiltering(t *testing.T) {
|
||||
t.Errorf("AlbumCoverProvider[0].ID = %q, want %q", albumProviders[0].ID(), "alb")
|
||||
}
|
||||
}
|
||||
|
||||
// Each provider's identity and out-of-the-box state. Settings boot reads
|
||||
// DefaultEnabled to decide which providers a new server asks, and the admin
|
||||
// screen reads RequiresAPIKey to decide which ask for a key.
|
||||
func TestProviders_IdentityAndDefaults(t *testing.T) {
|
||||
resetRegistryForTests()
|
||||
defer resetRegistryForTests()
|
||||
for _, tc := range []struct {
|
||||
p Provider
|
||||
id string
|
||||
needsKey, enabledNew bool
|
||||
}{
|
||||
{newMBCAAProvider(FetcherConfig{}), "mbcaa", false, true},
|
||||
{&theAudioDBProvider{}, "theaudiodb", true, true},
|
||||
{&deezerProvider{}, "deezer", false, true},
|
||||
{&lastfmProvider{}, "lastfm", true, false},
|
||||
} {
|
||||
if tc.p.ID() != tc.id || tc.p.RequiresAPIKey() != tc.needsKey || tc.p.DefaultEnabled() != tc.enabledNew {
|
||||
t.Errorf("%s: id %q, needs a key %v, on by default %v; want %q, %v, %v", tc.id,
|
||||
tc.p.ID(), tc.p.RequiresAPIKey(), tc.p.DefaultEnabled(), tc.id, tc.needsKey, tc.enabledNew)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,21 +39,6 @@ func newTheAudioDBProviderForTest(t *testing.T, mockURL string) *theAudioDBProvi
|
||||
return p
|
||||
}
|
||||
|
||||
func TestTheAudioDB_ID(t *testing.T) {
|
||||
resetRegistryForTests()
|
||||
defer resetRegistryForTests()
|
||||
p := &theAudioDBProvider{}
|
||||
if p.ID() != "theaudiodb" {
|
||||
t.Errorf("ID = %q, want theaudiodb", p.ID())
|
||||
}
|
||||
if !p.RequiresAPIKey() {
|
||||
t.Error("RequiresAPIKey = false, want true")
|
||||
}
|
||||
if !p.DefaultEnabled() {
|
||||
t.Error("DefaultEnabled = false, want true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheAudioDB_FetchAlbumCover_Success(t *testing.T) {
|
||||
imageBody := []byte("FAKE_JPEG")
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user