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:
@@ -45,7 +45,8 @@ func main() {
|
||||
go func() {
|
||||
sig := <-sigCh
|
||||
log.Printf("Received signal %v, shutting down...", sig)
|
||||
cancel()}()
|
||||
cancel()
|
||||
}()
|
||||
|
||||
app, err := NewApp(ctx, cfg)
|
||||
if err != nil {
|
||||
@@ -82,9 +83,6 @@ func NewApp(ctx context.Context, cfg *config.Config) (*App, error) {
|
||||
|
||||
// Close cleans up all application resources in reverse order of initialization.
|
||||
func (a *App) Close() {
|
||||
if a.mbClient != nil {
|
||||
a.mbClient.Close()
|
||||
}
|
||||
if a.db != nil {
|
||||
if err := a.db.Close(); err != nil {
|
||||
log.Printf("Error closing database: %v", err)
|
||||
|
||||
@@ -9,36 +9,6 @@ import (
|
||||
"naviwatcher/internal/config"
|
||||
)
|
||||
|
||||
func TestRun_GracefulShutdown(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
cfg := &config.Config{
|
||||
Server: config.ServerConfig{
|
||||
Host: "127.0.0.1",
|
||||
Port: 9090,
|
||||
},
|
||||
Navidrome: config.NavidromeConfig{
|
||||
URL: "http://localhost:4533",
|
||||
User: "test",
|
||||
Password: "test",
|
||||
},
|
||||
MusicBrainz: config.MusicBrainzConfig{
|
||||
UserAgent: "NaviWatcher/1.0 ( test@example.com )",
|
||||
},
|
||||
}
|
||||
|
||||
app, err := NewApp(ctx, cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("NewApp returned error: %v", err)
|
||||
}
|
||||
defer app.Close()
|
||||
|
||||
if err := app.run(ctx); err != nil {
|
||||
t.Fatalf("app.run returned error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigIntegration(t *testing.T) {
|
||||
// Integration test: write a minimal valid config and load it via config.LoadConfig,
|
||||
// verifying the full path that main() uses.
|
||||
@@ -77,10 +47,6 @@ musicbrainz:
|
||||
|
||||
func TestNewApp_CreatesMusicBrainzClient(t *testing.T) {
|
||||
// Verify that NewApp initializes the MusicBrainz client from config.
|
||||
dir := t.TempDir()
|
||||
dbPath := filepath.Join(dir, "test.db")
|
||||
_ = dbPath // database.New uses a hardcoded path in this version; we test the client creation.
|
||||
|
||||
cfg := &config.Config{
|
||||
Server: config.ServerConfig{
|
||||
Host: "127.0.0.1",
|
||||
|
||||
Reference in New Issue
Block a user