···23import (
4 "database/sql"
005 "testing"
6)
7···2021func setupAnnotationsTestDB(t *testing.T) *sql.DB {
22 t.Helper()
23- // Use file::memory: with cache=shared to ensure all connections share the same in-memory DB
24- db, err := InitDB("file::memory:?cache=shared", LibsqlConfig{})
025 if err != nil {
26 t.Fatalf("Failed to initialize test database: %v", err)
27 }
···23import (
4 "database/sql"
5+ "fmt"
6+ "strings"
7 "testing"
8)
9···2223func setupAnnotationsTestDB(t *testing.T) *sql.DB {
24 t.Helper()
25+ // Use a named in-memory DB unique to this test to ensure isolation between tests
26+ safeName := strings.ReplaceAll(t.Name(), "/", "_")
27+ db, err := InitDB(fmt.Sprintf("file:%s?mode=memory&cache=shared", safeName), LibsqlConfig{})
28 if err != nil {
29 t.Fatalf("Failed to initialize test database: %v", err)
30 }
+4-3
pkg/appview/db/device_store_test.go
···23import (
4 "context"
05 "strings"
6 "testing"
7 "time"
···12// setupTestDB creates an in-memory SQLite database for testing
13func setupTestDB(t *testing.T) *DeviceStore {
14 t.Helper()
15- // Use file::memory: with cache=shared to ensure all connections share the same in-memory DB
16- // This prevents race conditions where different connections see different databases
17- db, err := InitDB("file::memory:?cache=shared", LibsqlConfig{})
18 if err != nil {
19 t.Fatalf("Failed to initialize test database: %v", err)
20 }
···23import (
4 "context"
5+ "fmt"
6 "strings"
7 "testing"
8 "time"
···13// setupTestDB creates an in-memory SQLite database for testing
14func setupTestDB(t *testing.T) *DeviceStore {
15 t.Helper()
16+ // Use a named in-memory DB unique to this test to ensure isolation between tests
17+ safeName := strings.ReplaceAll(t.Name(), "/", "_")
18+ db, err := InitDB(fmt.Sprintf("file:%s?mode=memory&cache=shared", safeName), LibsqlConfig{})
19 if err != nil {
20 t.Fatalf("Failed to initialize test database: %v", err)
21 }
+5-4
pkg/appview/db/hold_store_test.go
···23import (
4 "database/sql"
005 "testing"
6 "time"
7)
···8081func setupHoldTestDB(t *testing.T) *sql.DB {
82 t.Helper()
83- // Use file::memory: with cache=shared to ensure all connections share the same in-memory DB
84- db, err := InitDB("file::memory:?cache=shared", LibsqlConfig{})
085 if err != nil {
86 t.Fatalf("Failed to initialize test database: %v", err)
87 }
88 // Limit to single connection to avoid race conditions in tests
89 db.SetMaxOpenConns(1)
90- // Clean slate: shared-cache in-memory DB may retain data from prior subtests
91- db.Exec("DELETE FROM hold_captain_records")
92 t.Cleanup(func() { db.Close() })
93 return db
94}
···23import (
4 "database/sql"
5+ "fmt"
6+ "strings"
7 "testing"
8 "time"
9)
···8283func setupHoldTestDB(t *testing.T) *sql.DB {
84 t.Helper()
85+ // Use a named in-memory DB unique to this test to ensure isolation between tests
86+ safeName := strings.ReplaceAll(t.Name(), "/", "_")
87+ db, err := InitDB(fmt.Sprintf("file:%s?mode=memory&cache=shared", safeName), LibsqlConfig{})
88 if err != nil {
89 t.Fatalf("Failed to initialize test database: %v", err)
90 }
91 // Limit to single connection to avoid race conditions in tests
92 db.SetMaxOpenConns(1)
0093 t.Cleanup(func() { db.Close() })
94 return db
95}
+4-2
pkg/appview/db/session_store_test.go
···23import (
4 "context"
05 "net/http"
6 "net/http/httptest"
7 "strings"
···12// setupSessionTestDB creates an in-memory SQLite database for testing
13func setupSessionTestDB(t *testing.T) *SessionStore {
14 t.Helper()
15- // Use file::memory: with cache=shared to ensure all connections share the same in-memory DB
16- db, err := InitDB("file::memory:?cache=shared", LibsqlConfig{})
017 if err != nil {
18 t.Fatalf("Failed to initialize test database: %v", err)
19 }
···23import (
4 "context"
5+ "fmt"
6 "net/http"
7 "net/http/httptest"
8 "strings"
···13// setupSessionTestDB creates an in-memory SQLite database for testing
14func setupSessionTestDB(t *testing.T) *SessionStore {
15 t.Helper()
16+ // Use a named in-memory DB unique to this test to ensure isolation between tests
17+ safeName := strings.ReplaceAll(t.Name(), "/", "_")
18+ db, err := InitDB(fmt.Sprintf("file:%s?mode=memory&cache=shared", safeName), LibsqlConfig{})
19 if err != nil {
20 t.Fatalf("Failed to initialize test database: %v", err)
21 }