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

Function setupTestEnv

pkg/e2e/sync/testutils.go:53–89  ·  view source on GitHub ↗

setupTestEnv creates an isolated test environment with its own database and temp directory

(t *testing.T)

Source from the content-addressed store, hash-verified

51
52// setupTestEnv creates an isolated test environment with its own database and temp directory
53func setupTestEnv(t *testing.T) testEnv {
54 tmpDir := t.TempDir()
55
56 // Create .dnote directory
57 dnoteDir := filepath.Join(tmpDir, consts.DnoteDirName)
58 if err := os.MkdirAll(dnoteDir, 0755); err != nil {
59 t.Fatal(errors.Wrap(err, "creating dnote directory"))
60 }
61
62 // Create database at the expected path
63 dbPath := filepath.Join(dnoteDir, consts.DnoteDBFileName)
64 db := cliDatabase.InitTestFileDBRaw(t, dbPath)
65
66 // Create server
67 server, serverDB := setupNewServer(t)
68
69 // Create config file with this server's endpoint
70 apiEndpoint := fmt.Sprintf("%s/api", server.URL)
71 updateConfigAPIEndpoint(t, tmpDir, apiEndpoint)
72
73 // Create command options with XDG paths pointing to temp dir
74 cmdOpts := clitest.RunDnoteCmdOptions{
75 Env: []string{
76 fmt.Sprintf("XDG_CONFIG_HOME=%s", tmpDir),
77 fmt.Sprintf("XDG_DATA_HOME=%s", tmpDir),
78 fmt.Sprintf("XDG_CACHE_HOME=%s", tmpDir),
79 },
80 }
81
82 return testEnv{
83 DB: db,
84 CmdOpts: cmdOpts,
85 Server: server,
86 ServerDB: serverDB,
87 TmpDir: tmpDir,
88 }
89}
90
91// setupTestServer creates a test server with its own database
92func setupTestServer(t *testing.T, serverTime time.Time) (*httptest.Server, *gorm.DB, error) {

Callers 8

TestSync_EmptyServerFunction · 0.70
testSyncCmdFunction · 0.70
TestSync_onewayFunction · 0.70
TestFullSyncFunction · 0.70

Calls 2

setupNewServerFunction · 0.85
updateConfigAPIEndpointFunction · 0.85

Tested by 7

TestSync_EmptyServerFunction · 0.56
TestSync_onewayFunction · 0.56
TestFullSyncFunction · 0.56