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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user