diff options
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 +} |
