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)
| 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. |
| 86 | func 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 |