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

Function InitTestCtxWithFileDB

pkg/cli/context/testutils.go:76–100  ·  view source on GitHub ↗

InitTestCtxWithFileDB initializes a test context with a file-based database at the expected path.

(t *testing.T)

Source from the content-addressed store, hash-verified

74// InitTestCtxWithFileDB initializes a test context with a file-based database
75// at the expected path.
76func 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}

Callers

nothing calls this directly

Calls 7

OpenFunction · 0.92
GetDefaultSchemaSQLFunction · 0.92
NewMockFunction · 0.92
getDefaultTestPathsFunction · 0.85
InitDnoteDirsFunction · 0.85
ExecMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected