All checks were successful
check / check (push) Successful in 3m22s
(*gorm.DB).Scan swaps GORM's own traceRecorder in for the configured
logger for the duration of the statement, and that recorder does not
implement gorm.ParamsFilter. The statement therefore reaches the log
with its bound values interpolated, which is the one path
(*gormlog.Logger).ParamsFilter cannot reach. internal/gormlog's
scan_guard_test.go exists to keep that path out of production code;
the queue-depth sampler landed with two calls on it, so next has been
failing make check on its own.
Both call sites now use Find, which goes through the normal query
callback. The emitted SQL is otherwise unchanged -- callbacks.Query
and callbacks.RowQuery share BuildQuerySQL, and both call sites set
Model and Select explicitly, so the table, the column list and the
soft-delete clause are built identically. Only the log line differs:
Scan: ... WHERE status IN ("pending","retrying") AND ...
Find: ... WHERE status IN (?,?) AND ...
TestQueueDepthSample_LogsNoBoundValue drives one sample through the
adapter and asserts the aggregate keeps its placeholders and carries
no status literal. Restoring either Scan fails it as well as the
static guard.
database.NewTestWebhookDBManagerWithLogger lets that test capture the
SQL the per-webhook databases emit; NewTestWebhookDBManager keeps its
signature and delegates to it.
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package database
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// NewTestDatabase creates a Database wrapper around a pre-opened *gorm.DB.
|
|
// Intended for use in tests that need a *database.Database without the
|
|
// full fx lifecycle. The caller is responsible for closing the underlying
|
|
// sql.DB connection.
|
|
func NewTestDatabase(db *gorm.DB) *Database {
|
|
return &Database{
|
|
db: db,
|
|
log: slog.New(slog.NewTextHandler(
|
|
os.Stderr,
|
|
&slog.HandlerOptions{Level: slog.LevelDebug},
|
|
)),
|
|
}
|
|
}
|
|
|
|
// NewTestWebhookDBManager creates a WebhookDBManager backed by the given
|
|
// data directory. Intended for use in tests without the fx lifecycle.
|
|
func NewTestWebhookDBManager(dataDir string) *WebhookDBManager {
|
|
return NewTestWebhookDBManagerWithLogger(
|
|
dataDir,
|
|
slog.New(slog.NewTextHandler(
|
|
os.Stderr,
|
|
&slog.HandlerOptions{Level: slog.LevelDebug},
|
|
)),
|
|
)
|
|
}
|
|
|
|
// NewTestWebhookDBManagerWithLogger is NewTestWebhookDBManager with the
|
|
// logger supplied by the caller. The per-webhook databases this manager
|
|
// opens hand that logger to gormlog, so a test that needs to see the SQL
|
|
// the service emits can capture it.
|
|
func NewTestWebhookDBManagerWithLogger(
|
|
dataDir string, log *slog.Logger,
|
|
) *WebhookDBManager {
|
|
return &WebhookDBManager{
|
|
dataDir: dataDir,
|
|
log: log,
|
|
}
|
|
}
|