fix: address code review findings
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"net/url"
|
||||
|
||||
"naviwatcher/internal/database"
|
||||
"naviwatcher/internal/normalize"
|
||||
)
|
||||
|
||||
// excludedStatuses contains release-group statuses that should be filtered out.
|
||||
@@ -112,20 +111,6 @@ func IsTypeIncluded(releaseType string) bool {
|
||||
return includedTypes[releaseType]
|
||||
}
|
||||
|
||||
// NormalizeString normalizes a string for fuzzy matching.
|
||||
// It delegates to the shared normalize package; see normalize.NormalizeString
|
||||
// for the full normalization contract.
|
||||
func NormalizeString(s string) string {
|
||||
return normalize.NormalizeString(s)
|
||||
}
|
||||
|
||||
// NormalizeArtistName normalizes an artist name for comparison.
|
||||
// It delegates to the shared normalize package; see
|
||||
// normalize.NormalizeArtistName for the full normalization contract.
|
||||
func NormalizeArtistName(name string) string {
|
||||
return normalize.NormalizeArtistName(name)
|
||||
}
|
||||
|
||||
// ToExternalRelease converts a ReleaseGroup to an ExternalRelease for database
|
||||
// persistence. artistID is the canonical artist key from artist_settings (the
|
||||
// Navidrome artist ID), which is what external_releases.artist_id references and
|
||||
|
||||
@@ -93,81 +93,6 @@ func TestFilterReleaseGroups_IgnoreCompilations(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- NormalizeString tests ----------
|
||||
|
||||
func TestNormalizeString_Basic(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
// Lowercase conversion
|
||||
{"DARK SIDE OF THE MOON", "dark side of the moon"},
|
||||
// Special character removal
|
||||
{"Dark Side of the Moon!", "dark side of the moon"},
|
||||
{"Dark-Side-of-the-Moon", "dark side of the moon"},
|
||||
{"Dark_Side_of_the_Moon", "dark side of the moon"},
|
||||
// Bracket removal
|
||||
{"Dark Side of the Moon [Deluxe Edition]", "dark side of the moon"},
|
||||
{"Dark Side of the Moon [Remastered 2020]", "dark side of the moon"},
|
||||
{"Album [2023 Remix]", "album"},
|
||||
// Parenthesis removal
|
||||
{"Dark Side of the Moon (Deluxe)", "dark side of the moon"},
|
||||
{"Album (Remastered)", "album"},
|
||||
// Year removal
|
||||
{"Dark Side of the Moon 1973", "dark side of the moon"},
|
||||
{"Album 2020 Remastered", "album remastered"},
|
||||
// Space collapsing
|
||||
{"Dark Side of the Moon", "dark side of the moon"},
|
||||
// Trim
|
||||
{" Dark Side of the Moon ", "dark side of the moon"},
|
||||
// Combined
|
||||
{"The Dark Side of the Moon [2011 Remaster] (Deluxe Edition)", "the dark side of the moon"},
|
||||
// Empty
|
||||
{"", ""},
|
||||
// Only special chars
|
||||
{"!@#$%^&*()", ""},
|
||||
// Digits that are not years should stay
|
||||
{"30 Seconds to Mars", "30 seconds to mars"},
|
||||
{"1941 - The Greatest Hits", "the greatest hits"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
got := NormalizeString(tt.input)
|
||||
if got != tt.expected {
|
||||
t.Errorf("NormalizeString(%q) = %q, want %q", tt.input, got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeArtistName(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"Pink Floyd", "pink floyd"},
|
||||
{"The Beatles", "beatles"},
|
||||
{"A Perfect Circle", "perfect circle"},
|
||||
{"An Orchestra", "orchestra"},
|
||||
{" The Who ", "who"},
|
||||
{"THE WHO", "who"},
|
||||
// No stripping needed
|
||||
{"Radiohead", "radiohead"},
|
||||
// Already stripped
|
||||
{"Beatles", "beatles"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
got := NormalizeArtistName(tt.input)
|
||||
if got != tt.expected {
|
||||
t.Errorf("NormalizeArtistName(%q) = %q, want %q", tt.input, got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- ReleaseGroup.ToExternalRelease tests ----------
|
||||
|
||||
func TestReleaseGroup_ToExternalRelease(t *testing.T) {
|
||||
|
||||
@@ -35,6 +35,12 @@ func NewClient(cfg config.MusicBrainzConfig) *MusicBrainzClient {
|
||||
}
|
||||
}
|
||||
|
||||
// Close releases resources held by the client, draining any idle keep-alive
|
||||
// connections so they don't linger until garbage collection.
|
||||
func (c *MusicBrainzClient) Close() {
|
||||
c.httpClient.CloseIdleConnections()
|
||||
}
|
||||
|
||||
// doGet performs a rate-limited HTTP GET request to the MusicBrainz API.
|
||||
// It blocks until the rate limiter allows the request, then sets the proper
|
||||
// User-Agent header and returns the response body.
|
||||
|
||||
Reference in New Issue
Block a user