fix(lidarr): wrap MBID-lookup decode errors with ErrInvalidPayload + fill test gaps

- Decode errors in LookupArtist/AlbumByMBID now wrap ErrInvalidPayload so
  callers can errors.Is the same way they do against the M5a methods.
- Tighten TestLookupAlbumByMBID_BadJSON to assert on ErrInvalidPayload.
- Add empty-mbid rejection tests for both methods.
- Add TestLookupArtistByMBID_EmptyArrayReturnsErrNotFound (only the album
  variant had the test before — symmetric coverage now).
- Normalize the network-error test's api key to key123 for consistency
  with the rest of delete_test.go.
This commit is contained in:
2026-04-30 17:01:50 -04:00
parent f2cdd23fd5
commit dbe0e79f54
2 changed files with 41 additions and 5 deletions
+39 -3
View File
@@ -86,8 +86,44 @@ func TestLookupAlbumByMBID_BadJSON(t *testing.T) {
defer srv.Close()
_, err := c.LookupAlbumByMBID(context.Background(), "x")
if err == nil {
t.Fatal("err = nil, want decode error")
if !errors.Is(err, ErrInvalidPayload) {
t.Errorf("err = %v, want ErrInvalidPayload", err)
}
}
func TestLookupAlbumByMBID_EmptyMBIDRejected(t *testing.T) {
c, srv := newTestClient(func(http.ResponseWriter, *http.Request) {
t.Error("server should not be called with empty mbid")
})
defer srv.Close()
if _, err := c.LookupAlbumByMBID(context.Background(), ""); err == nil {
t.Error("err = nil, want empty-mbid rejection")
}
}
func TestLookupArtistByMBID_EmptyArrayReturnsErrNotFound(t *testing.T) {
c, srv := newTestClient(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("[]"))
})
defer srv.Close()
_, err := c.LookupArtistByMBID(context.Background(), "x")
if !errors.Is(err, ErrNotFound) {
t.Errorf("err = %v, want ErrNotFound", err)
}
}
func TestLookupArtistByMBID_EmptyMBIDRejected(t *testing.T) {
c, srv := newTestClient(func(http.ResponseWriter, *http.Request) {
t.Error("server should not be called with empty mbid")
})
defer srv.Close()
if _, err := c.LookupArtistByMBID(context.Background(), ""); err == nil {
t.Error("err = nil, want empty-mbid rejection")
}
}
@@ -158,7 +194,7 @@ func TestDeleteAlbum_5xxReturnsErrServerError(t *testing.T) {
func TestDeleteAlbum_NetworkErrorReturnsErrUnreachable(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
srv.Close() // server is closed; client should fail to connect
c := NewClient(srv.URL, "test-key")
c := NewClient(srv.URL, "key123")
err := c.DeleteAlbum(context.Background(), 42, true, true)
if !errors.Is(err, ErrUnreachable) {