InitMemoryDB creates an in-memory SQLite database with the schema initialized
(t *testing.T)
| 47 | |
| 48 | // InitMemoryDB creates an in-memory SQLite database with the schema initialized |
| 49 | func InitMemoryDB(t *testing.T) *gorm.DB { |
| 50 | // Use file-based in-memory database with unique UUID per test to avoid sharing |
| 51 | uuid, err := helpers.GenUUID() |
| 52 | if err != nil { |
| 53 | t.Fatalf("failed to generate UUID for test database: %v", err) |
| 54 | } |
| 55 | dbName := fmt.Sprintf("file:%s?mode=memory&cache=shared", uuid) |
| 56 | db, err := gorm.Open(sqlite.Open(dbName), &gorm.Config{}) |
| 57 | if err != nil { |
| 58 | t.Fatalf("failed to open in-memory database: %v", err) |
| 59 | } |
| 60 | |
| 61 | database.InitSchema(db) |
| 62 | database.Migrate(db) |
| 63 | |
| 64 | return db |
| 65 | } |
| 66 | |
| 67 | // MustUUID generates a UUID and fails the test on error |
| 68 | func MustUUID(t *testing.T) string { |