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

Function TestInsertSystem

pkg/cli/database/queries_test.go:29–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestInsertSystem(t *testing.T) {
30 testCases := []struct {
31 key string
32 val string
33 }{
34 {
35 key: "foo",
36 val: "1558089284",
37 },
38 {
39 key: "baz",
40 val: "quz",
41 },
42 }
43
44 for _, tc := range testCases {
45 t.Run(fmt.Sprintf("insert %s %s", tc.key, tc.val), func(t *testing.T) {
46 // Setup
47 db := InitTestMemoryDB(t)
48
49 // execute
50 tx, err := db.Begin()
51 if err != nil {
52 t.Fatal(errors.Wrap(err, "beginning a transaction").Error())
53 }
54
55 if err := InsertSystem(tx, tc.key, tc.val); err != nil {
56 tx.Rollback()
57 t.Fatal(errors.Wrap(err, "executing for test case").Error())
58 }
59
60 tx.Commit()
61
62 // test
63 var key, val string
64 MustScan(t, "getting the saved record",
65 db.QueryRow("SELECT key, value FROM system WHERE key = ?", tc.key), &key, &val)
66
67 assert.Equal(t, key, tc.key, "key mismatch for test case")
68 assert.Equal(t, val, tc.val, "val mismatch for test case")
69 })
70 }
71}
72
73func TestUpsertSystem(t *testing.T) {
74 testCases := []struct {

Callers

nothing calls this directly

Calls 9

EqualFunction · 0.92
InitTestMemoryDBFunction · 0.85
InsertSystemFunction · 0.85
MustScanFunction · 0.85
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
QueryRowMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected