This commit is contained in:
Christoph K.
2026-04-07 09:49:17 +02:00
parent 063aa67615
commit 4db170b467
37 changed files with 269 additions and 48 deletions

View File

@@ -0,0 +1,3 @@
# Tester Agent Memory
- [Test database setup pattern](feedback_test_db_setup.md) — store.New appends query params; use os.CreateTemp instead of ":memory:" URIs

View File

@@ -0,0 +1,18 @@
---
name: Test database setup pattern
description: How to create isolated test databases for store and handler tests in this project
type: 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:
```go
f, _ := os.CreateTemp("", "krafttrainer-test-*.db")
f.Close()
dbPath := f.Name()
s, err := store.New(dbPath)
t.Cleanup(func() { s.Close(); os.Remove(dbPath) })
```