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

Function InitTestMemoryDBRaw

pkg/cli/database/testutils.go:86–108  ·  view source on GitHub ↗

InitTestMemoryDBRaw initializes an in-memory test database without marking migrations complete. If schemaPath is empty, uses the default schema. Used for migration testing.

(t *testing.T, schemaPath string)

Source from the content-addressed store, hash-verified

84// InitTestMemoryDBRaw initializes an in-memory test database without marking migrations complete.
85// If schemaPath is empty, uses the default schema. Used for migration testing.
86func InitTestMemoryDBRaw(t *testing.T, schemaPath string) *DB {
87 uuid := mustGenerateTestUUID(t)
88 dbName := fmt.Sprintf("file:%s?mode=memory&cache=shared", uuid)
89
90 db, err := Open(dbName)
91 if err != nil {
92 t.Fatal(errors.Wrap(err, "opening in-memory database"))
93 }
94
95 var schemaSQL string
96 if schemaPath != "" {
97 schemaSQL = string(utils.ReadFileAbs(schemaPath))
98 } else {
99 schemaSQL = defaultSchemaSQL
100 }
101
102 if _, err := db.Exec(schemaSQL); err != nil {
103 t.Fatal(errors.Wrap(err, "running schema sql"))
104 }
105
106 t.Cleanup(func() { db.Close() })
107 return db
108}
109
110// OpenTestDB opens the database connection to a test database
111// without initializing any schema

Callers 15

initTestDBNoMigrationFunction · 0.92
TestLocalMigration1Function · 0.92
TestLocalMigration2Function · 0.92
TestLocalMigration3Function · 0.92
TestLocalMigration4Function · 0.92
TestLocalMigration5Function · 0.92
TestLocalMigration6Function · 0.92
TestLocalMigration8Function · 0.92
TestLocalMigration9Function · 0.92

Calls 5

ReadFileAbsFunction · 0.92
mustGenerateTestUUIDFunction · 0.85
OpenFunction · 0.70
ExecMethod · 0.65
CloseMethod · 0.65

Tested by 15

initTestDBNoMigrationFunction · 0.74
TestLocalMigration1Function · 0.74
TestLocalMigration2Function · 0.74
TestLocalMigration3Function · 0.74
TestLocalMigration4Function · 0.74
TestLocalMigration5Function · 0.74
TestLocalMigration6Function · 0.74
TestLocalMigration8Function · 0.74
TestLocalMigration9Function · 0.74