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>
140 lines
3.9 KiB
Go
140 lines
3.9 KiB
Go
package coverart
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
// fakeProvider is a minimal Provider for registry tests. Does not
|
|
// implement any capability interface.
|
|
type fakeProvider struct {
|
|
id string
|
|
display string
|
|
requiresKey bool
|
|
defaultOn bool
|
|
}
|
|
|
|
func (f *fakeProvider) ID() string { return f.id }
|
|
func (f *fakeProvider) DisplayName() string { return f.display }
|
|
func (f *fakeProvider) RequiresAPIKey() bool { return f.requiresKey }
|
|
func (f *fakeProvider) DefaultEnabled() bool { return f.defaultOn }
|
|
func (f *fakeProvider) Configure(_ ProviderSettings) error { return nil }
|
|
|
|
// fakeAlbumProvider opts into the AlbumCoverProvider capability for
|
|
// the capability-filter test.
|
|
type fakeAlbumProvider struct {
|
|
fakeProvider
|
|
}
|
|
|
|
func (f *fakeAlbumProvider) FetchAlbumCover(_ context.Context, _ AlbumRef) ([]byte, error) {
|
|
return []byte("img"), nil
|
|
}
|
|
|
|
func TestRegister_AddsProvider(t *testing.T) {
|
|
resetRegistryForTests()
|
|
defer resetRegistryForTests()
|
|
|
|
p := &fakeProvider{id: "fake1", display: "Fake One"}
|
|
Register(p)
|
|
|
|
all := AllProviders()
|
|
if len(all) != 1 {
|
|
t.Fatalf("AllProviders len = %d, want 1", len(all))
|
|
}
|
|
if all[0].ID() != "fake1" {
|
|
t.Errorf("ID = %q, want %q", all[0].ID(), "fake1")
|
|
}
|
|
}
|
|
|
|
func TestRegister_PanicsOnDuplicateID(t *testing.T) {
|
|
resetRegistryForTests()
|
|
defer resetRegistryForTests()
|
|
|
|
Register(&fakeProvider{id: "dup"})
|
|
|
|
defer func() {
|
|
if r := recover(); r == nil {
|
|
t.Fatal("expected panic on duplicate ID")
|
|
}
|
|
}()
|
|
Register(&fakeProvider{id: "dup"}) // should panic
|
|
}
|
|
|
|
func TestProviderByID_Found(t *testing.T) {
|
|
resetRegistryForTests()
|
|
defer resetRegistryForTests()
|
|
|
|
Register(&fakeProvider{id: "x", display: "X"})
|
|
|
|
p, err := ProviderByID("x")
|
|
if err != nil {
|
|
t.Fatalf("err = %v, want nil", err)
|
|
}
|
|
if p.DisplayName() != "X" {
|
|
t.Errorf("display = %q, want %q", p.DisplayName(), "X")
|
|
}
|
|
}
|
|
|
|
func TestProviderByID_NotFound(t *testing.T) {
|
|
resetRegistryForTests()
|
|
defer resetRegistryForTests()
|
|
|
|
_, err := ProviderByID("missing")
|
|
if !errors.Is(err, ErrProviderNotFound) {
|
|
t.Errorf("err = %v, want ErrProviderNotFound", err)
|
|
}
|
|
}
|
|
|
|
func TestCapabilityFiltering(t *testing.T) {
|
|
resetRegistryForTests()
|
|
defer resetRegistryForTests()
|
|
|
|
plain := &fakeProvider{id: "plain"}
|
|
withAlbum := &fakeAlbumProvider{fakeProvider: fakeProvider{id: "alb"}}
|
|
Register(plain)
|
|
Register(withAlbum)
|
|
|
|
if got := len(AllProviders()); got != 2 {
|
|
t.Fatalf("AllProviders len = %d, want 2", got)
|
|
}
|
|
|
|
// Type-assert to count AlbumCoverProvider implementers — mimics
|
|
// what SettingsService.EnabledAlbumProviders does internally.
|
|
var albumProviders []AlbumCoverProvider
|
|
for _, p := range AllProviders() {
|
|
if ap, ok := p.(AlbumCoverProvider); ok {
|
|
albumProviders = append(albumProviders, ap)
|
|
}
|
|
}
|
|
if len(albumProviders) != 1 {
|
|
t.Fatalf("AlbumCoverProvider count = %d, want 1", len(albumProviders))
|
|
}
|
|
if albumProviders[0].ID() != "alb" {
|
|
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)
|
|
}
|
|
}
|
|
}
|