InitTestCtxWithFileDB initializes a test context with a file-based database at the expected path.
(t *testing.T)
| 74 | // InitTestCtxWithFileDB initializes a test context with a file-based database |
| 75 | // at the expected path. |
| 76 | func InitTestCtxWithFileDB(t *testing.T) DnoteCtx { |
| 77 | paths := getDefaultTestPaths(t) |
| 78 | |
| 79 | if err := InitDnoteDirs(paths); err != nil { |
| 80 | t.Fatal(errors.Wrap(err, "creating test directories")) |
| 81 | } |
| 82 | |
| 83 | dbPath := filepath.Join(paths.Data, consts.DnoteDirName, consts.DnoteDBFileName) |
| 84 | db, err := database.Open(dbPath) |
| 85 | if err != nil { |
| 86 | t.Fatal(errors.Wrap(err, "opening database")) |
| 87 | } |
| 88 | |
| 89 | if _, err := db.Exec(database.GetDefaultSchemaSQL()); err != nil { |
| 90 | t.Fatal(errors.Wrap(err, "running schema sql")) |
| 91 | } |
| 92 | |
| 93 | t.Cleanup(func() { db.Close() }) |
| 94 | |
| 95 | return DnoteCtx{ |
| 96 | DB: db, |
| 97 | Paths: paths, |
| 98 | Clock: clock.NewMock(), // Use a mock clock to test times |
| 99 | } |
| 100 | } |
nothing calls this directly
no test coverage detected