Files
krafttrainer/backend/.claude/agent-memory/tester/feedback_test_db_setup.md
Christoph K. 4db170b467 init
2026-04-07 09:49:17 +02:00

805 B

name, description, type
name description type
Test database setup pattern How to create isolated test databases for store and handler tests in this project feedback

Use os.CreateTemp to create a temporary SQLite file for each test. Pass that file path to store.New.

Why: store.New always appends ?_journal_mode=WAL&_foreign_keys=ON to the path argument. If you pass a URI like file:name?mode=memory&cache=shared, the result is a malformed DSN (...?mode=memory&cache=shared?_journal_mode=WAL&...) that SQLite rejects with "no such cache mode: shared".

How to apply: In every newTestStore / newHandlerWithStore helper, do:

f, _ := os.CreateTemp("", "krafttrainer-test-*.db")
f.Close()
dbPath := f.Name()
s, err := store.New(dbPath)
t.Cleanup(func() { s.Close(); os.Remove(dbPath) })