- Fix notifications_sent PK: changed from (rgid, sent_at) to rgid-only PK to prevent duplicate RGID rows across seconds. Use INSERT OR REPLACE instead of INSERT OR IGNORE for true idempotency. - Add foreign key constraints to DDL (artist_id references artist_settings, rgid references external_releases) per specification. - Enable PRAGMA foreign_keys=ON and PRAGMA busy_timeout=5000 for concurrent access safety. - Fix GetNotificationSentAt query: add ORDER BY sent_at DESC LIMIT 1 for deterministic results. - Fix config test: change YAML key from 'chat' to 'chat_id' to match struct tag, add ChatID assertion. - Fix migration tracking test: correct error message from "expected 4" to "expected 3". - Remove dead code in TestLoadConfig_InvalidPort: eliminate unused YAML template and remove port 0 case (valid, not invalid). - Remove unused path parameter from buildConfigWithPort helper. - Remove pointless 100ms sleep in run() and unused time import. - Remove tautological TestDefaultConfigPath test. - Update README.md: Go version 1.21+ to 1.25+, placeholder passwords to CHANGE_ME. - Update config.yaml.example: placeholder passwords to CHANGE_ME. - Update all database tests to insert parent rows first for FK satisfaction. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"naviwatcher/internal/config"
|
|
)
|
|
|
|
func TestRun_GracefulShutdown(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
|
|
cfg := &config.Config{}
|
|
if err := run(ctx, cfg); err != nil {
|
|
t.Fatalf("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.
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "config.yaml")
|
|
|
|
yaml := `server:
|
|
host: "127.0.0.1"
|
|
port: 9090
|
|
navidrome:
|
|
url: "http://localhost:4533"
|
|
user: "test"
|
|
password: "test"
|
|
musicbrainz:
|
|
user_agent: "NaviWatcher/1.0 ( test@example.com )"
|
|
`
|
|
if err := os.WriteFile(path, []byte(yaml), 0644); err != nil {
|
|
t.Fatalf("failed to write config: %v", err)
|
|
}
|
|
|
|
cfg, err := config.LoadConfig(path)
|
|
if err != nil {
|
|
t.Fatalf("LoadConfig returned error: %v", err)
|
|
}
|
|
|
|
if cfg.Server.Host != "127.0.0.1" {
|
|
t.Errorf("expected host 127.0.0.1, got %q", cfg.Server.Host)
|
|
}
|
|
if cfg.Server.Port != 9090 {
|
|
t.Errorf("expected port 9090, got %d", cfg.Server.Port)
|
|
}
|
|
if cfg.Navidrome.URL != "http://localhost:4533" {
|
|
t.Errorf("expected navidrome url http://localhost:4533, got %q", cfg.Navidrome.URL)
|
|
}
|
|
}
|