mirror of
https://github.com/docker/docker-agent.git
synced 2026-11-04 18:30:09 +00:00
pkg/session mixed the in-memory store with the file-backed constructor, so every embedder of pkg/runtime linked modernc.org/sqlite (large and slow to compile) even when using purely in-memory sessions. session.NewSQLiteSessionStore(ctx, path) becomes sqlitestore.New(ctx, path); behavior (open, migrate, backup+retry recovery) is unchanged. SQLiteSessionStore, NewSQLiteSessionStoreFromDB and the migrations stay in pkg/session - they only use database/sql and don't drag the driver. BREAKING CHANGE: callers of session.NewSQLiteSessionStore must import github.com/docker/docker-agent/pkg/session/sqlitestore and call New.
30 lines
746 B
Go
30 lines
746 B
Go
package session
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/docker/docker-agent/pkg/sqliteutil"
|
|
)
|
|
|
|
// newSQLiteStoreForTest opens a file-backed SQLite store the same way
|
|
// sqlitestore.New does on its happy path. In-package tests cannot import
|
|
// pkg/session/sqlitestore without an import cycle, and none of them exercise
|
|
// its backup/recovery logic (that is tested in sqlitestore itself).
|
|
func newSQLiteStoreForTest(t *testing.T, path string) (Store, error) {
|
|
t.Helper()
|
|
|
|
db, err := sqliteutil.OpenDB(t.Context(), path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
store, err := NewSQLiteSessionStoreFromDB(t.Context(), db)
|
|
if err != nil {
|
|
require.NoError(t, db.Close())
|
|
return nil, err
|
|
}
|
|
return store, nil
|
|
}
|