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

Function TestGetSystem

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

Source from the content-addressed store, hash-verified

127}
128
129func TestGetSystem(t *testing.T) {
130 t.Run(fmt.Sprintf("get string value"), func(t *testing.T) {
131 // Setup
132 db := InitTestMemoryDB(t)
133
134 // execute
135 MustExec(t, "inserting a system configuration", db, "INSERT INTO system (key, value) VALUES (?, ?)", "foo", "bar")
136
137 tx, err := db.Begin()
138 if err != nil {
139 t.Fatal(errors.Wrap(err, "beginning a transaction").Error())
140 }
141 var dest string
142 if err := GetSystem(tx, "foo", &dest); err != nil {
143 tx.Rollback()
144 t.Fatal(errors.Wrap(err, "executing for test case").Error())
145 }
146 tx.Commit()
147
148 // test
149 assert.Equal(t, dest, "bar", "dest mismatch")
150 })
151
152 t.Run(fmt.Sprintf("get int64 value"), func(t *testing.T) {
153 // Setup
154 db := InitTestMemoryDB(t)
155
156 // execute
157 MustExec(t, "inserting a system configuration", db, "INSERT INTO system (key, value) VALUES (?, ?)", "foo", 1234)
158
159 tx, err := db.Begin()
160 if err != nil {
161 t.Fatal(errors.Wrap(err, "beginning a transaction").Error())
162 }
163 var dest int64
164 if err := GetSystem(tx, "foo", &dest); err != nil {
165 tx.Rollback()
166 t.Fatal(errors.Wrap(err, "executing for test case").Error())
167 }
168 tx.Commit()
169
170 // test
171 assert.Equal(t, dest, int64(1234), "dest mismatch")
172 })
173}
174
175func TestUpdateSystem(t *testing.T) {
176 testCases := []struct {

Callers

nothing calls this directly

Calls 8

EqualFunction · 0.92
InitTestMemoryDBFunction · 0.85
GetSystemFunction · 0.85
MustExecFunction · 0.70
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected