Files
minstrel/internal/library/mbids_test.go
T

70 lines
1.8 KiB
Go

package library
import "testing"
func TestExtractMBIDs_ID3v2(t *testing.T) {
raw := map[string]interface{}{
"TXXX:MusicBrainz Album Id": "abc-123",
"TXXX:MusicBrainz Artist Id": "def-456",
}
a, ar := extractMBIDs(raw)
if a != "abc-123" || ar != "def-456" {
t.Errorf("got (%q, %q), want (\"abc-123\", \"def-456\")", a, ar)
}
}
func TestExtractMBIDs_Vorbis(t *testing.T) {
raw := map[string]interface{}{
"MUSICBRAINZ_ALBUMID": "abc",
"MUSICBRAINZ_ARTISTID": "def",
}
a, ar := extractMBIDs(raw)
if a != "abc" || ar != "def" {
t.Errorf("got (%q, %q)", a, ar)
}
}
func TestExtractMBIDs_MP4(t *testing.T) {
raw := map[string]interface{}{
"----:com.apple.iTunes:MusicBrainz Album Id": "abc",
"----:com.apple.iTunes:MusicBrainz Artist Id": "def",
}
a, ar := extractMBIDs(raw)
if a != "abc" || ar != "def" {
t.Errorf("got (%q, %q)", a, ar)
}
}
func TestExtractMBIDs_MissingKeysReturnEmpty(t *testing.T) {
a, ar := extractMBIDs(map[string]interface{}{})
if a != "" || ar != "" {
t.Errorf("got (%q, %q), want empty", a, ar)
}
}
func TestExtractMBIDs_MultiValueArtistTakesFirst(t *testing.T) {
// Some FLAC tags list collaborators as multi-value MUSICBRAINZ_ARTISTID.
// Minstrel uses the primary release artist; first wins.
raw := map[string]interface{}{
"MUSICBRAINZ_ARTISTID": []string{"primary-mbid", "collab-mbid"},
}
_, ar := extractMBIDs(raw)
if ar != "primary-mbid" {
t.Errorf("got %q, want %q", ar, "primary-mbid")
}
}
func TestExtractMBIDs_NilEntryIgnored(t *testing.T) {
raw := map[string]interface{}{
"TXXX:MusicBrainz Album Id": nil,
"TXXX:MusicBrainz Artist Id": "real-id",
}
a, ar := extractMBIDs(raw)
if a != "" {
t.Errorf("nil album entry should be ignored, got %q", a)
}
if ar != "real-id" {
t.Errorf("artist = %q", ar)
}
}