All checks were successful
check / check (push) Successful in 4s
Add comprehensive test coverage for three previously-untested packages: delivery (37% → 75%): - processNewTask with inline and large (DB-fetched) bodies - processRetryTask success, skip non-retrying, large body fetch - Worker lifecycle start/stop, retry channel processing - processDelivery unknown target type handling - recoverPendingDeliveries, recoverWebhookDeliveries, recoverInFlight - HTTP delivery with custom headers, timeout, invalid config - Notify batching middleware (0% → 70%): - Logging middleware status code capture and pass-through - LoggingResponseWriter delegation - CORS dev mode (allow-all) and prod mode (no-op) - RequireAuth redirect for unauthenticated, pass-through for authenticated - MetricsAuth basic auth validation - ipFromHostPort helper session (0% → 52%): - Get/Save round-trip with real cookie store - SetUser, GetUserID, GetUsername, IsAuthenticated - ClearUser removes all keys - Destroy invalidates session (MaxAge -1) - Session persistence across requests - Edge cases: overwrite user, wrong type, constants Test helpers added: - database.NewTestDatabase / NewTestWebhookDBManager for cross-package testing - session.NewForTest for middleware tests without fx lifecycle closes #28
29 lines
848 B
Go
29 lines
848 B
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 &WebhookDBManager{
|
|
dataDir: dataDir,
|
|
log: slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug})),
|
|
}
|
|
}
|