MCPcopy Index your code
hub / github.com/docker/docker-agent / openMemoryStore

Function openMemoryStore

pkg/session/store_memory_test.go:15–34  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
15func 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
36func TestNewSQLiteSessionStoreFromDB_NilDB(t *testing.T) {
37 t.Parallel()

Calls 5

ContextMethod · 0.80
OpenMethod · 0.65
CleanupMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected