fix: address code review findings
This commit is contained in:
@@ -360,18 +360,30 @@ func TestSyncAlbums_APIErrorMidSync(t *testing.T) {
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
// A transient failure for one artist must not abort the whole pull: the
|
||||
// failing artist is skipped (and logged) while the others succeed.
|
||||
err = SyncAlbums(ctx, nc, db)
|
||||
if err == nil {
|
||||
t.Fatal("SyncAlbums() expected error for API failure mid-sync, got nil")
|
||||
if err != nil {
|
||||
t.Fatalf("SyncAlbums() expected no fatal error on per-artist API failure, got %v", err)
|
||||
}
|
||||
|
||||
// The first artist's albums should have been stored before the error.
|
||||
// The first artist's albums should have been stored despite the second one
|
||||
// failing.
|
||||
albums1, err := database.GetLocalAlbumsByArtist(db, "1")
|
||||
if err != nil {
|
||||
t.Fatalf("GetLocalAlbumsByArtist(1) error: %v", err)
|
||||
}
|
||||
if len(albums1) != 1 {
|
||||
t.Errorf("expected 1 album for artist 1 (synced before error), got %d", len(albums1))
|
||||
t.Errorf("expected 1 album for artist 1 (synced before skip), got %d", len(albums1))
|
||||
}
|
||||
|
||||
// The failing artist should have no local albums stored.
|
||||
albums2, err := database.GetLocalAlbumsByArtist(db, "2")
|
||||
if err != nil {
|
||||
t.Fatalf("GetLocalAlbumsByArtist(2) error: %v", err)
|
||||
}
|
||||
if len(albums2) != 0 {
|
||||
t.Errorf("expected 0 albums for artist 2 (skipped on error), got %d", len(albums2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user