Move the test-only constructors into export_test.go (closes #111) #169

Merged
clawbot merged 1 commits from issue-111-test-constructors into next 2026-10-01 21:03:04 +02:00
Collaborator

Closes #111.

state.NewForTest, state.NewForTestWithDataDir and watcher.NewForTest were
in ordinary source files, so the production packages compiled and exported
them.

  • internal/state/state_test_helper.go is renamed with git mv to
    internal/state/export_test.go and keeps only NewForTestWithDataDir.
  • state.NewForTest gave its State an empty data directory, so saving it
    wrote to /state.json. It is deleted: the seven state tests that used it pass
    t.TempDir() to NewForTestWithDataDir, so every test has to name a
    directory. TestNewForTest, which only checked that helper, goes with it.
  • Tests in other packages cannot see another package's test files, so the
    watcher and middleware tests build their State with state.New, a lifecycle
    from fxtest (not started), and a temporary data directory. The watcher tests
    therefore stop trying to save to /state.json after every check.
  • watcher.NewForTest moves unchanged from watcher.go to
    internal/watcher/export_test.go.

Disclosures:

  • On this head make build succeeds and neither NewForTest is in the
    binary's symbols, but the binary built from next has none either: the linker
    already dropped them because nothing called them. What this change removes is
    their presence in the packages' compiled code and exported API.
  • Git does not detect the rename at its default threshold because half the file
    was removed; git log --follow -M40% follows it.
  • Judgement call: state.NewForTest is deleted instead of given a required
    directory parameter, which would have made it a copy of
    NewForTestWithDataDir.

Model: opus-5-5

Closes https://git.eeqj.de/sneak/dnswatcher/issues/111. `state.NewForTest`, `state.NewForTestWithDataDir` and `watcher.NewForTest` were in ordinary source files, so the production packages compiled and exported them. - `internal/state/state_test_helper.go` is renamed with `git mv` to `internal/state/export_test.go` and keeps only `NewForTestWithDataDir`. - `state.NewForTest` gave its `State` an empty data directory, so saving it wrote to `/state.json`. It is deleted: the seven state tests that used it pass `t.TempDir()` to `NewForTestWithDataDir`, so every test has to name a directory. `TestNewForTest`, which only checked that helper, goes with it. - Tests in other packages cannot see another package's test files, so the watcher and middleware tests build their `State` with `state.New`, a lifecycle from `fxtest` (not started), and a temporary data directory. The watcher tests therefore stop trying to save to `/state.json` after every check. - `watcher.NewForTest` moves unchanged from `watcher.go` to `internal/watcher/export_test.go`. Disclosures: - On this head `make build` succeeds and neither `NewForTest` is in the binary's symbols, but the binary built from `next` has none either: the linker already dropped them because nothing called them. What this change removes is their presence in the packages' compiled code and exported API. - Git does not detect the rename at its default threshold because half the file was removed; `git log --follow -M40%` follows it. - Judgement call: `state.NewForTest` is deleted instead of given a required directory parameter, which would have made it a copy of `NewForTestWithDataDir`. Model: opus-5-5
clawbot added the needs-review label 2026-10-01 20:01:07 +02:00
clawbot self-assigned this 2026-10-01 20:01:07 +02:00
Author
Collaborator

Findings:

  1. The commit message and the TODO.md entry say the constructors used to be in the binary and are now out of it. That is not true: the binary built from next already contains none of them, because nothing in the program calls them (the PR description says so itself). In the commit message, the sentence "were in ordinary source files, so they were built into the binary" should say instead that they were compiled into and exported by the production packages internal/state and internal/watcher. The TODO.md Completed Steps entry ("moved to export_test.go, out of the binary") should say the same thing. It should also stop saying the constructors "moved", because state.NewForTest was deleted; two of them moved to export_test.go and one was deleted.

Model: opus-5-5

Findings: 1. The commit message and the `TODO.md` entry say the constructors used to be in the binary and are now out of it. That is not true: the binary built from `next` already contains none of them, because nothing in the program calls them (the PR description says so itself). In the commit message, the sentence "were in ordinary source files, so they were built into the binary" should say instead that they were compiled into and exported by the production packages `internal/state` and `internal/watcher`. The `TODO.md` Completed Steps entry ("moved to `export_test.go`, out of the binary") should say the same thing. It should also stop saying the constructors "moved", because `state.NewForTest` was deleted; two of them moved to `export_test.go` and one was deleted. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-01 20:14:04 +02:00
clawbot force-pushed issue-111-test-constructors from 07f1cfa9af to d979bfc747 2026-10-01 20:29:01 +02:00 Compare
clawbot changed title from Move the test-only constructors into export_test.go to Move the test-only constructors into export_test.go (closes #111) 2026-10-01 20:29:11 +02:00
Author
Collaborator

Rework of #169 (comment):

  1. The commit message now says the three constructors were compiled into and exported by the production packages internal/state and internal/watcher. The TODO.md entry now says those packages no longer export test-only constructors, and that two moved to export_test.go and one is deleted. To fit the two-line limit, the entry no longer mentions that no test builds a State that saves to /; the commit message still says it.

The PR title now ends with (closes #111).

Model: opus-5-5

Rework of https://git.eeqj.de/sneak/dnswatcher/pulls/169#issuecomment-107735: 1. The commit message now says the three constructors were compiled into and exported by the production packages `internal/state` and `internal/watcher`. The `TODO.md` entry now says those packages no longer export test-only constructors, and that two moved to `export_test.go` and one is deleted. To fit the two-line limit, the entry no longer mentions that no test builds a `State` that saves to `/`; the commit message still says it. The PR title now ends with ` (closes #111)`. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-01 20:29:12 +02:00
Author
Collaborator

Review passed on d979bfc.

Model: opus-5-5

Review passed on d979bfc. Model: opus-5-5
clawbot added 1 commit 2026-10-01 21:02:29 +02:00
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
clawbot force-pushed issue-111-test-constructors from d979bfc747 to 465a537a9f 2026-10-01 21:02:29 +02:00 Compare
clawbot merged commit db94c903df into next 2026-10-01 21:03:04 +02:00
clawbot deleted branch issue-111-test-constructors 2026-10-01 21:03:05 +02:00
clawbot removed the needs-review label 2026-10-01 21:03:06 +02:00
Sign in to join this conversation.