fix: address code review findings

Remove dead code: duplicate ExternalRelease/Artist/ParsedArtist structs in
model.go, ParseArtist/mbArtist/mbArtistData in client.go, ArtistTypeFilter
and related filtering functions in api.go, SyncArtistDiscographyWithFilter
in sync.go, and CacheStats/IsArtistCacheValid in cache.go.

Fix bugs: SaveExternalRelease now stores NULL instead of empty string for
zero CachedAt; sync upserts are now transactional with stale release cleanup;
getCachedReleases returns int instead of *CacheStats; doGet uses url.Values
for proper query encoding of MBID.

Fix tests: removed duplicate TestRun_GracefulShutdown, removed dead code
(_ = dbPath) from TestNewApp, fixed assertions in httptest handler goroutine
to avoid data race, increased rate limiter timing tolerance, removed
Client.Close() calls (no-op removed), fixed sync test cache expiry to use
UPDATE instead of 0 TTL races.

Fix formatting: cancel()}() formatting in main.go, error format string in sync.go.
This commit is contained in:
2026-05-26 14:10:22 +03:00
parent 34ea84fc77
commit a5911c257c
13 changed files with 199 additions and 864 deletions

View File

@@ -168,34 +168,3 @@ func TestParseReleaseGroups_WithStatus(t *testing.T) {
t.Errorf("ReleaseGroups[0].Status = %q, want %q", result.ReleaseGroups[0].Status, "Bootleg")
}
}
func TestParseArtist_Success(t *testing.T) {
data := []byte(`<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
<artist id="artist-uuid-1" type="Group">
<name>Pink Floyd</name>
</artist>
</metadata>`)
result, err := ParseArtist(data)
if err != nil {
t.Fatalf("ParseArtist() error = %v", err)
}
if result.ID != "artist-uuid-1" {
t.Errorf("ParseArtist().ID = %q, want %q", result.ID, "artist-uuid-1")
}
if result.Name != "Pink Floyd" {
t.Errorf("ParseArtist().Name = %q, want %q", result.Name, "Pink Floyd")
}
}
func TestParseArtist_MalformedXML(t *testing.T) {
data := []byte(`this is not xml`)
_, err := ParseArtist(data)
if err == nil {
t.Fatal("ParseArtist() expected error for malformed XML, got nil")
}
}