Keep test helpers out of the shipped binary (closes #506)
check / check (push) Successful in 10m29s

The four testing.go files in config, database, middleware and session
are gone. ClearEnvForTest moves to internal/config/configtest; the
webhook database manager helpers move to internal/database/databasetest
and the middleware's NewForTest to internal/middleware/middlewaretest,
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
This commit is contained in:
2026-10-06 07:16:09 +00:00
parent a9d77e20d7
commit 49c7aefc97
39 changed files with 332 additions and 320 deletions
+7 -6
View File
@@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/require"
"sneak.berlin/go/webhooker/internal/config"
"sneak.berlin/go/webhooker/internal/middleware"
"sneak.berlin/go/webhooker/internal/middleware/middlewaretest"
)
const (
@@ -70,8 +71,8 @@ func metricsTestRouter(
Environment: "prod",
ReceiverRateLimit: receiverLimit,
}
m := middleware.NewForTest(
log, cfg, newTestSessionManager(cfg, log, nil),
m := middlewaretest.NewForTest(
t, log, cfg, newTestSessionManager(t, cfg),
)
reg := prometheus.NewRegistry()
@@ -456,9 +457,9 @@ func TestMetrics_StatusAndSizeStillRecorded(t *testing.T) {
}
// TestMetrics_WorksOnNewForTestMiddleware pins that a Middleware built
// by NewForTest has a recorder of its own: its Metrics() serves a
// request instead of panicking, and a second one does not collide
// with the first.
// by middlewaretest.NewForTest has a recorder of its own: its Metrics()
// serves a request instead of panicking, and a second one does not
// collide with the first.
func TestMetrics_WorksOnNewForTestMiddleware(t *testing.T) {
t.Parallel()
@@ -469,7 +470,7 @@ func TestMetrics_WorksOnNewForTestMiddleware(t *testing.T) {
})
for range 2 {
h := middleware.NewForTest(log, cfg, nil).Metrics()(ok)
h := middlewaretest.NewForTest(t, log, cfg, nil).Metrics()(ok)
req := httptest.NewRequestWithContext(
t.Context(), http.MethodGet, okRoute, nil,