fix: address code review findings
This commit is contained in:
@@ -137,12 +137,13 @@ func TestParseReleaseGroups_MalformedXML(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseReleaseGroups_WithStatus(t *testing.T) {
|
||||
func TestParseReleaseGroups_PrimaryAndSecondaryTypes(t *testing.T) {
|
||||
data := []byte(`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
|
||||
<release-group-list count="1">
|
||||
<release-group id="rg-bootleg" type="Album" status="Bootleg">
|
||||
<title>Unofficial Live Recording</title>
|
||||
<release-group-list count="2">
|
||||
<release-group id="rg-album" type="Album">
|
||||
<title>Studio Album</title>
|
||||
<primary-type>Album</primary-type>
|
||||
<first-release-date>2020-01-01</first-release-date>
|
||||
<artist-credit>
|
||||
<name-credit>
|
||||
@@ -152,6 +153,22 @@ func TestParseReleaseGroups_WithStatus(t *testing.T) {
|
||||
</name-credit>
|
||||
</artist-credit>
|
||||
</release-group>
|
||||
<release-group id="rg-comp" type="Album Compilation">
|
||||
<title>Greatest Hits</title>
|
||||
<primary-type>Album</primary-type>
|
||||
<secondary-type-list>
|
||||
<secondary-type>Compilation</secondary-type>
|
||||
<secondary-type>Live</secondary-type>
|
||||
</secondary-type-list>
|
||||
<first-release-date>2021-05-05</first-release-date>
|
||||
<artist-credit>
|
||||
<name-credit>
|
||||
<artist id="artist-uuid-2">
|
||||
<name>Test Artist</name>
|
||||
</artist>
|
||||
</name-credit>
|
||||
</artist-credit>
|
||||
</release-group>
|
||||
</release-group-list>
|
||||
</metadata>`)
|
||||
|
||||
@@ -160,11 +177,39 @@ func TestParseReleaseGroups_WithStatus(t *testing.T) {
|
||||
t.Fatalf("ParseReleaseGroups() error = %v", err)
|
||||
}
|
||||
|
||||
if len(result.ReleaseGroups) != 1 {
|
||||
t.Fatalf("ParseReleaseGroups() returned %d groups, want 1", len(result.ReleaseGroups))
|
||||
if len(result.ReleaseGroups) != 2 {
|
||||
t.Fatalf("ParseReleaseGroups() returned %d groups, want 2", len(result.ReleaseGroups))
|
||||
}
|
||||
|
||||
if result.ReleaseGroups[0].Status != "Bootleg" {
|
||||
t.Errorf("ReleaseGroups[0].Status = %q, want %q", result.ReleaseGroups[0].Status, "Bootleg")
|
||||
byID := make(map[string]ReleaseGroup)
|
||||
for _, rg := range result.ReleaseGroups {
|
||||
byID[rg.ID] = rg
|
||||
}
|
||||
|
||||
album := byID["rg-album"]
|
||||
if album.Type != "Album" {
|
||||
t.Errorf("rg-album.Type = %q, want %q", album.Type, "Album")
|
||||
}
|
||||
if len(album.SecondaryTypes) != 0 {
|
||||
t.Errorf("rg-album.SecondaryTypes = %v, want empty", album.SecondaryTypes)
|
||||
}
|
||||
|
||||
comp := byID["rg-comp"]
|
||||
if comp.Type != "Album" {
|
||||
t.Errorf("rg-comp.Type = %q, want %q", comp.Type, "Album")
|
||||
}
|
||||
// Release groups have no status attribute; the secondary type list is the
|
||||
// authoritative source for classifications like Compilation.
|
||||
if !contains(comp.SecondaryTypes, "Compilation") || !contains(comp.SecondaryTypes, "Live") {
|
||||
t.Errorf("rg-comp.SecondaryTypes = %v, want Compilation and Live", comp.SecondaryTypes)
|
||||
}
|
||||
}
|
||||
|
||||
func contains(s []string, want string) bool {
|
||||
for _, v := range s {
|
||||
if v == want {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user