openMemoryStore returns a SQLiteSessionStore backed by an in-memory database and a t.Cleanup that closes it. Tests use this to avoid the overhead of allocating a temp directory and writing WAL files to disk.
(t *testing.T)
| 13 | // and a t.Cleanup that closes it. Tests use this to avoid the overhead of |
| 14 | // allocating a temp directory and writing WAL files to disk. |
| 15 | func openMemoryStore(t *testing.T) *SQLiteSessionStore { |
| 16 | t.Helper() |
| 17 | // SQLite ":memory:" databases are private to a single connection, so the |
| 18 | // store's MaxOpenConns=1 setting (applied by sqliteutil for file DBs) is |
| 19 | // implicitly satisfied here too. We open with database/sql directly so |
| 20 | // the test does not depend on a working filesystem. |
| 21 | db, err := sql.Open("sqlite", ":memory:") |
| 22 | require.NoError(t, err) |
| 23 | // Register the db cleanup before any potentially failing call so the |
| 24 | // connection is released even if NewSQLiteSessionStoreFromDB returns an |
| 25 | // error. Calling Close on an already-closed *sql.DB is a no-op, so the |
| 26 | // store.Close() registered below is harmless when both run. |
| 27 | t.Cleanup(func() { _ = db.Close() }) |
| 28 | db.SetMaxOpenConns(1) |
| 29 | |
| 30 | store, err := NewSQLiteSessionStoreFromDB(t.Context(), db) |
| 31 | require.NoError(t, err) |
| 32 | t.Cleanup(func() { _ = store.Close() }) |
| 33 | return store |
| 34 | } |
| 35 | |
| 36 | func TestNewSQLiteSessionStoreFromDB_NilDB(t *testing.T) { |
| 37 | t.Parallel() |
no test coverage detected