fix(coverart/test): use newHTTPClient in provider test fixtures
This commit is contained in:
@@ -18,7 +18,7 @@ func newDeezerTestProvider(t *testing.T, baseURL string) *deezerProvider {
|
||||
deezerBaseURL = baseURL
|
||||
t.Cleanup(func() { deezerBaseURL = old })
|
||||
|
||||
p := &deezerProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &deezerProvider{client: newHTTPClient(httpClientOptions{Name: "deezer", HTTPClient: &http.Client{Timeout: 5 * time.Second}, BaseBackoff: time.Millisecond})}
|
||||
p.enabled.Store(true)
|
||||
return p
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func TestDeezer_FetchArtistArt_NameMismatch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeezer_FetchArtistArt_EmptyName(t *testing.T) {
|
||||
p := &deezerProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &deezerProvider{client: newHTTPClient(httpClientOptions{Name: "deezer", HTTPClient: &http.Client{Timeout: 5 * time.Second}, BaseBackoff: time.Millisecond})}
|
||||
p.enabled.Store(true)
|
||||
_, _, err := p.FetchArtistArt(context.Background(), ArtistRef{})
|
||||
if !errors.Is(err, ErrNotFound) {
|
||||
@@ -102,7 +102,7 @@ func TestDeezer_FetchArtistArt_EmptyName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeezer_FetchArtistArt_Disabled(t *testing.T) {
|
||||
p := &deezerProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &deezerProvider{client: newHTTPClient(httpClientOptions{Name: "deezer", HTTPClient: &http.Client{Timeout: 5 * time.Second}, BaseBackoff: time.Millisecond})}
|
||||
// enabled defaults to false
|
||||
_, _, err := p.FetchArtistArt(context.Background(), ArtistRef{Name: "X"})
|
||||
if !errors.Is(err, ErrNotFound) {
|
||||
@@ -150,7 +150,7 @@ func TestDeezer_FetchAlbumCover_TitleMismatch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeezer_FetchAlbumCover_MissingFields(t *testing.T) {
|
||||
p := &deezerProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &deezerProvider{client: newHTTPClient(httpClientOptions{Name: "deezer", HTTPClient: &http.Client{Timeout: 5 * time.Second}, BaseBackoff: time.Millisecond})}
|
||||
p.enabled.Store(true)
|
||||
|
||||
cases := []AlbumRef{
|
||||
|
||||
@@ -19,7 +19,7 @@ func newLastfmTestProvider(t *testing.T, baseURL, key string) *lastfmProvider {
|
||||
lastfmBaseURL = baseURL
|
||||
t.Cleanup(func() { lastfmBaseURL = prevBase })
|
||||
|
||||
p := &lastfmProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &lastfmProvider{client: newHTTPClient(httpClientOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
||||
p.enabled.Store(true)
|
||||
p.apiKey.Store(&key)
|
||||
return p
|
||||
@@ -177,7 +177,7 @@ 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: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &lastfmProvider{client: newHTTPClient(httpClientOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
||||
p.enabled.Store(true)
|
||||
emptyKey := ""
|
||||
p.apiKey.Store(&emptyKey)
|
||||
@@ -190,7 +190,7 @@ func TestLastfm_FetchArtistArt_EmptyAPIKey(t *testing.T) {
|
||||
|
||||
func TestLastfm_FetchArtistArt_Disabled(t *testing.T) {
|
||||
// Key set but disabled.
|
||||
p := &lastfmProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &lastfmProvider{client: newHTTPClient(httpClientOptions{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)
|
||||
@@ -203,7 +203,7 @@ func TestLastfm_FetchArtistArt_Disabled(t *testing.T) {
|
||||
|
||||
func TestLastfm_FetchArtistArt_EmptyRefs(t *testing.T) {
|
||||
// Neither MBID nor Name: ErrNotFound without making any HTTP call.
|
||||
p := &lastfmProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &lastfmProvider{client: newHTTPClient(httpClientOptions{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)
|
||||
@@ -301,7 +301,7 @@ func TestLastfm_FetchAlbumCover_WithMBIDHint(t *testing.T) {
|
||||
// ── FetchAlbumCover — missing fields ─────────────────────────────────────────
|
||||
|
||||
func TestLastfm_FetchAlbumCover_MissingFields(t *testing.T) {
|
||||
p := &lastfmProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &lastfmProvider{client: newHTTPClient(httpClientOptions{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)
|
||||
@@ -320,7 +320,7 @@ func TestLastfm_FetchAlbumCover_MissingFields(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLastfm_FetchAlbumCover_EmptyAPIKey(t *testing.T) {
|
||||
p := &lastfmProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &lastfmProvider{client: newHTTPClient(httpClientOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
||||
p.enabled.Store(true)
|
||||
emptyKey := ""
|
||||
p.apiKey.Store(&emptyKey)
|
||||
@@ -332,7 +332,7 @@ func TestLastfm_FetchAlbumCover_EmptyAPIKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLastfm_FetchAlbumCover_Disabled(t *testing.T) {
|
||||
p := &lastfmProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &lastfmProvider{client: newHTTPClient(httpClientOptions{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)
|
||||
|
||||
@@ -28,7 +28,7 @@ func newTheAudioDBProviderForTest(t *testing.T, mockURL string) *theAudioDBProvi
|
||||
withTheAudioDBBaseURL(t, mockURL)
|
||||
|
||||
p := &theAudioDBProvider{
|
||||
client: &http.Client{Timeout: 5 * time.Second},
|
||||
client: newHTTPClient(httpClientOptions{Name: "theaudiodb", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond}),
|
||||
}
|
||||
Register(p)
|
||||
p.enabled.Store(true)
|
||||
@@ -234,7 +234,7 @@ func TestTheAudioDB_DefaultsToTestKeyOnEmpty(t *testing.T) {
|
||||
defer resetRegistryForTests()
|
||||
withTheAudioDBBaseURL(t, srv.URL)
|
||||
|
||||
p := &theAudioDBProvider{client: &http.Client{Timeout: 5 * time.Second}}
|
||||
p := &theAudioDBProvider{client: newHTTPClient(httpClientOptions{Name: "theaudiodb", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
||||
Register(p)
|
||||
// Configure with empty key — should fall back to test key.
|
||||
if err := p.Configure(ProviderSettings{Enabled: true, APIKey: ""}); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user