package testutil import ( "database/sql" "net/http" "testing" "time" "github.com/alexedwards/scs/sqlite3store" "github.com/alexedwards/scs/v2" ) // NewTestSessionManager creates an SCS session manager backed by the // provided SQLite database. The background cleanup goroutine is stopped // automatically when the test finishes. func NewTestSessionManager(t *testing.T, db *sql.DB) *scs.SessionManager { t.Helper() store := sqlite3store.New(db) t.Cleanup(func() { store.StopCleanup() }) sm := scs.New() sm.Store = store sm.Lifetime = 30 * 24 * time.Hour sm.Cookie.Path = "/" sm.Cookie.HttpOnly = true sm.Cookie.Secure = false sm.Cookie.SameSite = http.SameSiteLaxMode return sm }