diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-30 11:48:05 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-30 11:48:05 +0300 |
| commit | 38e318e71d50e4340ddbf1ae63b3d85e958b4644 (patch) | |
| tree | 9b858ea44c139d98049780c19b89d5cf469ce161 /cmd/mediaplayer/main_test.go | |
| parent | af29461e3a21de9b4aafbc741c5b8b0af36d1ced (diff) | |
fa: wire GCWorker startup and shutdown in cmd/mediaplayer/main.go
- Refactor main into run(args) for testability and clean error propagation.
- Create slog.Logger from cfg.LogLevel using TextHandler.
- Instantiate service.NewGCWorker with store, clock, cfg.MediaRoot, and
time.Duration(cfg.GCIntervalMinutes)*time.Minute.
- Start GCWorker after construction and defer Stop for graceful shutdown.
- Add cmd/mediaplayer/main_test.go as an integration smoke test wiring the
GCWorker against a real SQLite store.
Diffstat (limited to 'cmd/mediaplayer/main_test.go')
| -rw-r--r-- | cmd/mediaplayer/main_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/cmd/mediaplayer/main_test.go b/cmd/mediaplayer/main_test.go new file mode 100644 index 0000000..08b9d92 --- /dev/null +++ b/cmd/mediaplayer/main_test.go @@ -0,0 +1,47 @@ +package main + +import ( + "log/slog" + "os" + "path/filepath" + "testing" + "time" + + "codeberg.org/snonux/play/internal" + "codeberg.org/snonux/play/internal/clock" + "codeberg.org/snonux/play/internal/repository" + "codeberg.org/snonux/play/internal/service" +) + +// TestGCWorkerWiring verifies that the GC worker can be constructed with the +// same dependencies used in main, started, and stopped cleanly against a real +// SQLite store. This is an integration-friendly smoke test for the wiring. +func TestGCWorkerWiring(t *testing.T) { + tmpDir := t.TempDir() + dbPath := filepath.Join(tmpDir, "test.db") + mediaRoot := filepath.Join(tmpDir, "media") + if err := os.MkdirAll(mediaRoot, 0o755); err != nil { + t.Fatalf("mkdir media root: %v", err) + } + + store, err := repository.Open(dbPath) + if err != nil { + t.Fatalf("open db: %v", err) + } + defer func() { + if err := store.Close(); err != nil { + t.Logf("close db: %v", err) + } + }() + + cfg := &internal.Config{ + GCIntervalMinutes: 1, + } + + logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})) + clk := clock.RealClock{} + + w := service.NewGCWorker(store, clk, mediaRoot, time.Duration(cfg.GCIntervalMinutes)*time.Minute, logger) + w.Start() + w.Stop() // must not panic even after interacting with real store +} |
