MCPcopy
hub / github.com/dnote/dnote / TestInitSystemKV_existing

Function TestInitSystemKV_existing

pkg/cli/infra/init_test.go:61–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestInitSystemKV_existing(t *testing.T) {
62 // Setup
63 db := database.InitTestMemoryDB(t)
64
65 database.MustExec(t, "inserting a system config", db, "INSERT INTO system (key, value) VALUES (?, ?)", "testKey", "testVal")
66
67 var originalCount int
68 database.MustScan(t, "counting system configs", db.QueryRow("SELECT count(*) FROM system"), &originalCount)
69
70 // Execute
71 tx, err := db.Begin()
72 if err != nil {
73 t.Fatal(errors.Wrap(err, "beginning a transaction"))
74 }
75
76 if err := initSystemKV(tx, "testKey", "newTestVal"); err != nil {
77 tx.Rollback()
78 t.Fatal(errors.Wrap(err, "executing"))
79 }
80
81 tx.Commit()
82
83 // Test
84 var count int
85 database.MustScan(t, "counting system configs", db.QueryRow("SELECT count(*) FROM system"), &count)
86 assert.Equal(t, count, originalCount, "system count mismatch")
87
88 var val string
89 database.MustScan(t, "getting system value",
90 db.QueryRow("SELECT value FROM system WHERE key = ?", "testKey"), &val)
91 assert.Equal(t, val, "testVal", "system value should not have been updated")
92}
93
94func TestInit_APIEndpoint(t *testing.T) {
95 // Create a temporary directory for test

Callers

nothing calls this directly

Calls 9

InitTestMemoryDBFunction · 0.92
MustExecFunction · 0.92
MustScanFunction · 0.92
EqualFunction · 0.92
initSystemKVFunction · 0.85
QueryRowMethod · 0.65
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected