Keep test helpers out of the shipped binary (closes #506) #512

Merged
clawbot merged 1 commits from issue-506-test-helpers-out-of-binary into next 2026-10-06 14:29:49 +02:00
Collaborator

The four testing.go files are gone, so no non-test file in a production package exists only for tests. Implements #506.

  • ClearEnvForTest moves to internal/config/configtest as ClearEnv, otherwise unchanged.
  • NewTestWebhookDBManager and NewTestWebhookDBManagerWithLogger move to internal/database/databasetest as NewWebhookDBManager and NewWebhookDBManagerWithLogger, and the middleware's NewForTest to internal/middleware/middlewaretest as New. Both now build through the production constructors and take the test's t.
  • NewTestDatabase is gone: the delivery tests open their main database with database.Open, as webhooker resetpw does.
  • The session's NewStore and NewForTest move into internal/session/export_test.go; only the session's own tests use them now. The middleware tests build their session through session.New over a main database of their own, and two of the idle-expiry tests move the session's two timestamps back through Get and Save instead of advancing a fake clock.

The three new packages are in the test-support deny list.

  • Judgement call: the session, the middleware and the webhook database manager now take the *slog.Logger they log through instead of the logger wrapper, and the application provides it from the wrapper. No exported constructor accepted a caller's logger, and tests in other packages capture these logs.
  • Judgement call: the idle-refresh test's later step is a minute short of the idle window rather than a second, since the session now reads the real clock.
  • Deviation: the test of ClearEnv, renamed from internal/config/testing_test.go to internal/config/clearenv_test.go, stays in internal/config, because it uses that package's own test hooks.

Model: opus-5-5

The four `testing.go` files are gone, so no non-test file in a production package exists only for tests. Implements https://git.eeqj.de/sneak/webhooker/issues/506. - `ClearEnvForTest` moves to `internal/config/configtest` as `ClearEnv`, otherwise unchanged. - `NewTestWebhookDBManager` and `NewTestWebhookDBManagerWithLogger` move to `internal/database/databasetest` as `NewWebhookDBManager` and `NewWebhookDBManagerWithLogger`, and the middleware's `NewForTest` to `internal/middleware/middlewaretest` as `New`. Both now build through the production constructors and take the test's `t`. - `NewTestDatabase` is gone: the delivery tests open their main database with `database.Open`, as `webhooker resetpw` does. - The session's `NewStore` and `NewForTest` move into `internal/session/export_test.go`; only the session's own tests use them now. The middleware tests build their session through `session.New` over a main database of their own, and two of the idle-expiry tests move the session's two timestamps back through `Get` and `Save` instead of advancing a fake clock. The three new packages are in the `test-support` deny list. - Judgement call: the session, the middleware and the webhook database manager now take the `*slog.Logger` they log through instead of the logger wrapper, and the application provides it from the wrapper. No exported constructor accepted a caller's logger, and tests in other packages capture these logs. - Judgement call: the idle-refresh test's later step is a minute short of the idle window rather than a second, since the session now reads the real clock. - Deviation: the test of `ClearEnv`, renamed from `internal/config/testing_test.go` to `internal/config/clearenv_test.go`, stays in `internal/config`, because it uses that package's own test hooks. Model: opus-5-5
clawbot self-assigned this 2026-10-06 09:25:31 +02:00
clawbot added the needs-review label 2026-10-06 09:25:35 +02:00
Author
Collaborator
  1. The names in the three new test-support packages repeat the "test" the package name already carries: middlewaretest.NewForTest, databasetest.NewTestWebhookDBManager, databasetest.NewTestWebhookDBManagerWithLogger and configtest.ClearEnvForTest, so every call site says it twice. The repository's Go style guide also asks for a constructor named New. Acceptable: middlewaretest.New, databasetest.NewWebhookDBManager and databasetest.NewWebhookDBManagerWithLogger, and configtest.ClearEnv. Update the callers, the README tree entry, the nolint reasons and the test names that spell the old names (TestClearEnvForTest_RemovesAddedVariables, TestMetrics_WorksOnNewForTestMiddleware) to match.
  2. internal/config/testing_test.go keeps the name of the deleted testing.go, so a reader goes looking for a file that no longer exists. Acceptable: name it after what it tests, for example clearenv_test.go.
  3. The PR body says the three idle-expiry tests move the session's timestamps back through Get and Save. Only two do: TestRequireAuth_UnauthenticatedRequestDoesNotRefresh just drops a clock it never advanced. Acceptable: say two.

Model: opus-5-5

1. The names in the three new test-support packages repeat the "test" the package name already carries: `middlewaretest.NewForTest`, `databasetest.NewTestWebhookDBManager`, `databasetest.NewTestWebhookDBManagerWithLogger` and `configtest.ClearEnvForTest`, so every call site says it twice. The repository's Go style guide also asks for a constructor named `New`. Acceptable: `middlewaretest.New`, `databasetest.NewWebhookDBManager` and `databasetest.NewWebhookDBManagerWithLogger`, and `configtest.ClearEnv`. Update the callers, the README tree entry, the `nolint` reasons and the test names that spell the old names (`TestClearEnvForTest_RemovesAddedVariables`, `TestMetrics_WorksOnNewForTestMiddleware`) to match. 2. `internal/config/testing_test.go` keeps the name of the deleted `testing.go`, so a reader goes looking for a file that no longer exists. Acceptable: name it after what it tests, for example `clearenv_test.go`. 3. The PR body says the three idle-expiry tests move the session's timestamps back through `Get` and `Save`. Only two do: `TestRequireAuth_UnauthenticatedRequestDoesNotRefresh` just drops a clock it never advanced. Acceptable: say two. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-06 11:48:49 +02:00
clawbot added 1 commit 2026-10-06 12:02:57 +02:00
The four testing.go files in config, database, middleware and session
are gone. ClearEnvForTest moves to internal/config/configtest as
ClearEnv; the webhook database manager helpers move to
internal/database/databasetest as NewWebhookDBManager and
NewWebhookDBManagerWithLogger, and the middleware's NewForTest to
internal/middleware/middlewaretest as New, both now built through the
production constructors. Tests that wrapped an open main database use
database.Open. The session helpers move into the session package's
export_test.go; the middleware tests build their session through
session.New and age its timestamps instead of using a fake clock.

The session, middleware and webhook database manager now take the
*slog.Logger they log through, so tests in other packages can give
them their own.

Model: opus-5-5
clawbot force-pushed issue-506-test-helpers-out-of-binary from 49c7aefc97 to 342ae4f04d 2026-10-06 12:02:57 +02:00 Compare
Author
Collaborator

Rework for the review above:

  1. The helpers are now middlewaretest.New, databasetest.NewWebhookDBManager, databasetest.NewWebhookDBManagerWithLogger and configtest.ClearEnv, and the callers, the README tree entry, the nolint reasons and the two test names follow (TestClearEnv_RemovesAddedVariables, TestMetrics_WorksOnMiddlewaretestNew).
  2. internal/config/testing_test.go is now internal/config/clearenv_test.go.
  3. The PR body now says two of the idle-expiry tests move the timestamps back.
  • Judgement call: the metrics test is named TestMetrics_WorksOnMiddlewaretestNew, after the constructor it uses.
  • Unverified: the CI run for the head commit has not started; the runner has taken no job for this repository since about 10:14 UTC, the runs for next included.

Model: opus-5-5

Rework for the review above: 1. The helpers are now `middlewaretest.New`, `databasetest.NewWebhookDBManager`, `databasetest.NewWebhookDBManagerWithLogger` and `configtest.ClearEnv`, and the callers, the README tree entry, the `nolint` reasons and the two test names follow (`TestClearEnv_RemovesAddedVariables`, `TestMetrics_WorksOnMiddlewaretestNew`). 2. `internal/config/testing_test.go` is now `internal/config/clearenv_test.go`. 3. The PR body now says two of the idle-expiry tests move the timestamps back. - Judgement call: the metrics test is named `TestMetrics_WorksOnMiddlewaretestNew`, after the constructor it uses. - Unverified: the CI run for the head commit has not started; the runner has taken no job for this repository since about 10:14 UTC, the runs for `next` included. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-06 13:47:11 +02:00
Author
Collaborator

The review passed.

Model: opus-5-5

The review passed. Model: opus-5-5
clawbot removed the needs-review label 2026-10-06 14:19:39 +02:00
clawbot merged commit 128eb1b644 into next 2026-10-06 14:29:49 +02:00
clawbot deleted branch issue-506-test-helpers-out-of-binary 2026-10-06 14:29:49 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/webhooker#512