(t *testing.T)
| 173 | } |
| 174 | |
| 175 | func TestUpdateSystem(t *testing.T) { |
| 176 | testCases := []struct { |
| 177 | key string |
| 178 | val string |
| 179 | countDelta int |
| 180 | }{ |
| 181 | { |
| 182 | key: "foo", |
| 183 | val: "1558089284", |
| 184 | }, |
| 185 | { |
| 186 | key: "foo", |
| 187 | val: "bar", |
| 188 | }, |
| 189 | } |
| 190 | |
| 191 | for _, tc := range testCases { |
| 192 | t.Run(fmt.Sprintf("update %s %s", tc.key, tc.val), func(t *testing.T) { |
| 193 | // Setup |
| 194 | db := InitTestMemoryDB(t) |
| 195 | |
| 196 | MustExec(t, "inserting a system configuration", db, "INSERT INTO system (key, value) VALUES (?, ?)", "foo", "fuz") |
| 197 | MustExec(t, "inserting a system configuration", db, "INSERT INTO system (key, value) VALUES (?, ?)", "baz", "quz") |
| 198 | |
| 199 | var initialSystemCount int |
| 200 | MustScan(t, "counting records", db.QueryRow("SELECT count(*) FROM system"), &initialSystemCount) |
| 201 | |
| 202 | // execute |
| 203 | tx, err := db.Begin() |
| 204 | if err != nil { |
| 205 | t.Fatal(errors.Wrap(err, "beginning a transaction").Error()) |
| 206 | } |
| 207 | |
| 208 | if err := UpdateSystem(tx, tc.key, tc.val); err != nil { |
| 209 | tx.Rollback() |
| 210 | t.Fatal(errors.Wrap(err, "executing for test case").Error()) |
| 211 | } |
| 212 | |
| 213 | tx.Commit() |
| 214 | |
| 215 | // test |
| 216 | var key, val string |
| 217 | MustScan(t, "getting the saved record", |
| 218 | db.QueryRow("SELECT key, value FROM system WHERE key = ?", tc.key), &key, &val) |
| 219 | var systemCount int |
| 220 | MustScan(t, "counting records", |
| 221 | db.QueryRow("SELECT count(*) FROM system"), &systemCount) |
| 222 | |
| 223 | assert.Equal(t, key, tc.key, "key mismatch") |
| 224 | assert.Equal(t, val, tc.val, "val mismatch") |
| 225 | assert.Equal(t, systemCount, initialSystemCount, "count mismatch") |
| 226 | }) |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | func TestGetActiveNote(t *testing.T) { |
| 231 | t.Run("not deleted", func(t *testing.T) { |
nothing calls this directly
no test coverage detected