fix: address code review findings

This commit is contained in:
2026-07-19 19:45:08 +03:00
parent beef81d598
commit a7803615cd
7 changed files with 185 additions and 94 deletions

View File

@@ -12,33 +12,35 @@ import (
// ---------- FilterReleaseGroups tests ----------
func TestFilterReleaseGroups_ExcludesBootlegPromotionPseudo(t *testing.T) {
// Release groups carry no status in ws/2, so status values are irrelevant to
// filtering. These groups differ only by the (ignored) status attribute; all
// are Album/Single and should be retained.
func TestFilterReleaseGroups_StatusIsNotFiltered(t *testing.T) {
groups := []ReleaseGroup{
{ID: "rg-1", Title: "Official Album", Type: "Album", Status: "Official"},
{ID: "rg-2", Title: "Bootleg Live", Type: "Album", Status: "Bootleg"},
{ID: "rg-3", Title: "Promo CD", Type: "Single", Status: "Promotion"},
{ID: "rg-4", Title: "Pseudo Release", Type: "Album", Status: "Pseudo-Release"},
{ID: "rg-1", Title: "Official Album", Type: "Album"},
{ID: "rg-2", Title: "Bootleg Live", Type: "Album"},
{ID: "rg-3", Title: "Promo CD", Type: "Single"},
{ID: "rg-4", Title: "Pseudo Release", Type: "Album"},
}
result := FilterReleaseGroups(groups, FilterOptions{})
if len(result) != 1 {
t.Fatalf("FilterReleaseGroups() returned %d groups, want 1", len(result))
}
if result[0].ID != "rg-1" {
t.Errorf("FilterReleaseGroups()[0].ID = %q, want %q", result[0].ID, "rg-1")
if len(result) != 4 {
t.Fatalf("FilterReleaseGroups() returned %d groups, want 4", len(result))
}
}
func TestFilterReleaseGroups_IncludesOnlyAllowedTypes(t *testing.T) {
groups := []ReleaseGroup{
{ID: "rg-1", Title: "Album", Type: "Album", Status: "Official"},
{ID: "rg-2", Title: "Single", Type: "Single", Status: "Official"},
{ID: "rg-3", Title: "EP", Type: "EP", Status: "Official"},
{ID: "rg-4", Title: "Compilation", Type: "Compilation", Status: "Official"},
{ID: "rg-5", Title: "Soundtrack", Type: "Soundtrack", Status: "Official"},
{ID: "rg-6", Title: "Live", Type: "Live", Status: "Official"},
{ID: "rg-7", Title: "Remix", Type: "Remix", Status: "Official"},
{ID: "rg-1", Title: "Album", Type: "Album"},
{ID: "rg-2", Title: "Single", Type: "Single"},
{ID: "rg-3", Title: "EP", Type: "EP"},
// A compilation whose primary type is Album (the common case) is
// classified via its secondary type and must be included.
{ID: "rg-4", Title: "Greatest Hits", Type: "Album", SecondaryTypes: []string{"Compilation"}},
{ID: "rg-5", Title: "Soundtrack", Type: "Soundtrack"},
{ID: "rg-6", Title: "Live", Type: "Live"},
{ID: "rg-7", Title: "Remix", Type: "Remix"},
}
result := FilterReleaseGroups(groups, FilterOptions{})
@@ -57,9 +59,11 @@ func TestFilterReleaseGroups_IncludesOnlyAllowedTypes(t *testing.T) {
func TestFilterReleaseGroups_IgnoreSingles(t *testing.T) {
groups := []ReleaseGroup{
{ID: "rg-1", Title: "Album", Type: "Album", Status: "Official"},
{ID: "rg-2", Title: "Single", Type: "Single", Status: "Official"},
{ID: "rg-3", Title: "EP", Type: "EP", Status: "Official"},
{ID: "rg-1", Title: "Album", Type: "Album"},
{ID: "rg-2", Title: "Single", Type: "Single"},
{ID: "rg-3", Title: "EP", Type: "EP"},
// Single expressed via secondary type (primary is Album).
{ID: "rg-4", Title: "Single from Album", Type: "Album", SecondaryTypes: []string{"Single"}},
}
result := FilterReleaseGroups(groups, FilterOptions{IgnoreSingles: true})
@@ -68,7 +72,7 @@ func TestFilterReleaseGroups_IgnoreSingles(t *testing.T) {
t.Fatalf("FilterReleaseGroups() returned %d groups, want 2", len(result))
}
for _, rg := range result {
if rg.Type == "Single" {
if rg.Type == "Single" || contains(rg.SecondaryTypes, "Single") {
t.Errorf("single %q should have been filtered out", rg.ID)
}
}
@@ -76,9 +80,9 @@ func TestFilterReleaseGroups_IgnoreSingles(t *testing.T) {
func TestFilterReleaseGroups_IgnoreCompilations(t *testing.T) {
groups := []ReleaseGroup{
{ID: "rg-1", Title: "Album", Type: "Album", Status: "Official"},
{ID: "rg-2", Title: "Compilation", Type: "Compilation", Status: "Official"},
{ID: "rg-3", Title: "EP", Type: "EP", Status: "Official"},
{ID: "rg-1", Title: "Album", Type: "Album"},
{ID: "rg-2", Title: "Greatest Hits", Type: "Album", SecondaryTypes: []string{"Compilation"}},
{ID: "rg-3", Title: "EP", Type: "EP"},
}
result := FilterReleaseGroups(groups, FilterOptions{IgnoreCompilations: true})
@@ -87,7 +91,7 @@ func TestFilterReleaseGroups_IgnoreCompilations(t *testing.T) {
t.Fatalf("FilterReleaseGroups() returned %d groups, want 2", len(result))
}
for _, rg := range result {
if rg.Type == "Compilation" {
if rg.Type == "Compilation" || contains(rg.SecondaryTypes, "Compilation") {
t.Errorf("compilation %q should have been filtered out", rg.ID)
}
}
@@ -100,7 +104,6 @@ func TestReleaseGroup_ToExternalRelease(t *testing.T) {
ID: "rg-uuid-1",
Title: "Dark Side of the Moon",
Type: "Album",
Status: "Official",
ArtistID: "mbid-artist-uuid-1",
ArtistName: "Pink Floyd",
ReleaseDate: "1973-03-01",