tests: move the test-only constructors into export_test.go (closes #111)
check / check (push) Successful in 1m37s

state.NewForTest, state.NewForTestWithDataDir and watcher.NewForTest
were compiled into and exported by the production packages
internal/state and internal/watcher. NewForTestWithDataDir and
watcher.NewForTest now live in their package's export_test.go. Tests in
other packages cannot see those files, so the watcher and middleware
tests build their State with state.New and a temporary data directory;
the watcher tests no longer try to save to /state.json.
state.NewForTest, whose State saved to /, is deleted: the state tests
that used it pass t.TempDir() to NewForTestWithDataDir, and the test of
the helper itself is gone.

Model: opus-5-5
This commit was merged in pull request #169.
This commit is contained in:
2026-10-01 21:03:03 +02:00
parent 5493e28480
commit db94c903df
8 changed files with 88 additions and 98 deletions
+9 -1
View File
@@ -276,10 +276,18 @@ func newTestHandlers(t *testing.T) *handlers.Handlers {
t.Fatalf("notify.New: %v", err)
}
st, err := state.New(fxtest.NewLifecycle(t), state.Params{
Logger: log,
Config: &config.Config{DataDir: t.TempDir()},
})
if err != nil {
t.Fatalf("state.New: %v", err)
}
hnd, err := handlers.New(nil, handlers.Params{
Logger: log,
Globals: glob,
State: state.NewForTest(),
State: st,
Notify: notifier,
})
if err != nil {