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

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
This commit is contained in:
2026-10-06 10:02:49 +00:00
parent 3de345fe6f
commit 342ae4f04d
39 changed files with 342 additions and 330 deletions
+6 -3
View File
@@ -18,6 +18,7 @@ import (
"gorm.io/gorm"
"sneak.berlin/go/webhooker/internal/config"
"sneak.berlin/go/webhooker/internal/database"
"sneak.berlin/go/webhooker/internal/database/databasetest"
"sneak.berlin/go/webhooker/internal/globals"
"sneak.berlin/go/webhooker/internal/logger"
)
@@ -50,7 +51,7 @@ func setupTestWebhookDBManager(
lc,
database.WebhookDBManagerParams{
Config: cfg,
Logger: l,
Logger: l.Get(),
},
)
require.NoError(t, err)
@@ -117,7 +118,8 @@ func TestWebhookDBManager_ConcurrentFirstTouchOpensOnce(t *testing.T) {
var logs bytes.Buffer
mgr := database.NewTestWebhookDBManagerWithLogger(
mgr := databasetest.NewWebhookDBManagerWithLogger(
t,
t.TempDir(),
slog.New(slog.NewTextHandler(&logs, nil)),
)
@@ -307,7 +309,8 @@ func TestWebhookDBManager_LostDatabaseIsLogged(t *testing.T) {
var logs bytes.Buffer
mgr := database.NewTestWebhookDBManagerWithLogger(
mgr := databasetest.NewWebhookDBManagerWithLogger(
t,
t.TempDir(),
slog.New(slog.NewTextHandler(&logs, nil)),
)