MCPcopy
hub / github.com/dnote/dnote / TestInit

Function TestInit

pkg/cli/main_test.go:58–108  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestInit(t *testing.T) {
59 testDir, opts := setupTestEnv(t)
60
61 // Execute
62 // run an arbitrary command "view" due to https://github.com/spf13/cobra/issues/1056
63 testutils.RunDnoteCmd(t, opts, binaryName, "view")
64
65 db := database.OpenTestDB(t, testDir)
66
67 // Test
68 ok, err := utils.FileExists(testDir)
69 if err != nil {
70 t.Fatal(errors.Wrap(err, "checking if dnote dir exists"))
71 }
72 if !ok {
73 t.Errorf("dnote directory was not initialized")
74 }
75
76 ok, err = utils.FileExists(fmt.Sprintf("%s/%s/%s", testDir, consts.DnoteDirName, consts.ConfigFilename))
77 if err != nil {
78 t.Fatal(errors.Wrap(err, "checking if dnote config exists"))
79 }
80 if !ok {
81 t.Errorf("config file was not initialized")
82 }
83
84 var notesTableCount, booksTableCount, systemTableCount int
85 database.MustScan(t, "counting notes",
86 db.QueryRow("SELECT count(*) FROM sqlite_master WHERE type = ? AND name = ?", "table", "notes"), &notesTableCount)
87 database.MustScan(t, "counting books",
88 db.QueryRow("SELECT count(*) FROM sqlite_master WHERE type = ? AND name = ?", "table", "books"), &booksTableCount)
89 database.MustScan(t, "counting system",
90 db.QueryRow("SELECT count(*) FROM sqlite_master WHERE type = ? AND name = ?", "table", "system"), &systemTableCount)
91
92 assert.Equal(t, notesTableCount, 1, "notes table count mismatch")
93 assert.Equal(t, booksTableCount, 1, "books table count mismatch")
94 assert.Equal(t, systemTableCount, 1, "system table count mismatch")
95
96 // test that all default system configurations are generated
97 var lastUpgrade, lastMaxUSN, lastSyncAt string
98 database.MustScan(t, "scanning last upgrade",
99 db.QueryRow("SELECT value FROM system WHERE key = ?", consts.SystemLastUpgrade), &lastUpgrade)
100 database.MustScan(t, "scanning last max usn",
101 db.QueryRow("SELECT value FROM system WHERE key = ?", consts.SystemLastMaxUSN), &lastMaxUSN)
102 database.MustScan(t, "scanning last sync at",
103 db.QueryRow("SELECT value FROM system WHERE key = ?", consts.SystemLastSyncAt), &lastSyncAt)
104
105 assert.NotEqual(t, lastUpgrade, "", "last upgrade should not be empty")
106 assert.NotEqual(t, lastMaxUSN, "", "last max usn should not be empty")
107 assert.NotEqual(t, lastSyncAt, "", "last sync at should not be empty")
108}
109
110func TestAddNote(t *testing.T) {
111 t.Run("new book", func(t *testing.T) {

Callers

nothing calls this directly

Calls 8

RunDnoteCmdFunction · 0.92
OpenTestDBFunction · 0.92
FileExistsFunction · 0.92
MustScanFunction · 0.92
EqualFunction · 0.92
NotEqualFunction · 0.92
setupTestEnvFunction · 0.70
QueryRowMethod · 0.65

Tested by

no test coverage detected