MCPcopy Index your code
hub / github.com/dnote/dnote / InitMemoryDB

Function InitMemoryDB

pkg/server/testutils/main.go:49–65  ·  view source on GitHub ↗

InitMemoryDB creates an in-memory SQLite database with the schema initialized

(t *testing.T)

Source from the content-addressed store, hash-verified

47
48// InitMemoryDB creates an in-memory SQLite database with the schema initialized
49func 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
68func MustUUID(t *testing.T) string {

Callers 15

TestGetTokenFunction · 0.92
TestViewNoteFunction · 0.92
TestGetNotesFunction · 0.92
TestGetNoteFunction · 0.92
TestCreateNoteFunction · 0.92
TestDeleteNoteFunction · 0.92
TestUpdateNoteFunction · 0.92
TestNotSupportedVersionsFunction · 0.92
TestGetBooksFunction · 0.92
TestGetBooksByNameFunction · 0.92
TestGetBookFunction · 0.92
TestGetBookNonOwnerFunction · 0.92

Calls 4

GenUUIDFunction · 0.92
InitSchemaFunction · 0.92
MigrateFunction · 0.92
OpenMethod · 0.80

Tested by 15

TestGetTokenFunction · 0.74
TestViewNoteFunction · 0.74
TestGetNotesFunction · 0.74
TestGetNoteFunction · 0.74
TestCreateNoteFunction · 0.74
TestDeleteNoteFunction · 0.74
TestUpdateNoteFunction · 0.74
TestNotSupportedVersionsFunction · 0.74
TestGetBooksFunction · 0.74
TestGetBooksByNameFunction · 0.74
TestGetBookFunction · 0.74
TestGetBookNonOwnerFunction · 0.74