(t *testing.T)
| 199 | } |
| 200 | |
| 201 | func TestSyncDeleteNote(t *testing.T) { |
| 202 | t.Run("exists on server only", func(t *testing.T) { |
| 203 | // set up |
| 204 | db := database.InitTestMemoryDB(t) |
| 205 | |
| 206 | // execute |
| 207 | tx, err := db.Begin() |
| 208 | if err != nil { |
| 209 | t.Fatal(errors.Wrap(err, "beginning a transaction").Error()) |
| 210 | } |
| 211 | |
| 212 | if err := syncDeleteNote(tx, "nonexistent-note-uuid"); err != nil { |
| 213 | tx.Rollback() |
| 214 | t.Fatal(errors.Wrap(err, "executing").Error()) |
| 215 | } |
| 216 | |
| 217 | tx.Commit() |
| 218 | |
| 219 | // test |
| 220 | var noteCount, bookCount int |
| 221 | database.MustScan(t, "counting notes", db.QueryRow("SELECT count(*) FROM notes"), ¬eCount) |
| 222 | database.MustScan(t, "counting books", db.QueryRow("SELECT count(*) FROM books"), &bookCount) |
| 223 | |
| 224 | assert.Equalf(t, noteCount, 0, "note count mismatch") |
| 225 | assert.Equalf(t, bookCount, 0, "book count mismatch") |
| 226 | }) |
| 227 | |
| 228 | t.Run("local copy is dirty", func(t *testing.T) { |
| 229 | b1UUID := testutils.MustGenerateUUID(t) |
| 230 | |
| 231 | // set up |
| 232 | db := database.InitTestMemoryDB(t) |
| 233 | |
| 234 | database.MustExec(t, "inserting b1 for test case %d", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", b1UUID, "b1-label") |
| 235 | database.MustExec(t, "inserting n1 for test case %d", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n1-uuid", b1UUID, 10, "n1 body", 1541108743, false, true) |
| 236 | database.MustExec(t, "inserting n2 for test case %d", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n2-uuid", b1UUID, 11, "n2 body", 1541108743, false, true) |
| 237 | |
| 238 | var n1 database.Note |
| 239 | database.MustScan(t, "getting n1 for test case", |
| 240 | db.QueryRow("SELECT uuid, book_uuid, usn, added_on, edited_on, body, deleted, dirty FROM notes WHERE uuid = ?", "n1-uuid"), |
| 241 | &n1.UUID, &n1.BookUUID, &n1.USN, &n1.AddedOn, &n1.EditedOn, &n1.Body, &n1.Deleted, &n1.Dirty) |
| 242 | var n2 database.Note |
| 243 | database.MustScan(t, "getting n2 for test case", |
| 244 | db.QueryRow("SELECT uuid, book_uuid, usn, added_on, edited_on, body, deleted, dirty FROM notes WHERE uuid = ?", "n2-uuid"), |
| 245 | &n2.UUID, &n2.BookUUID, &n2.USN, &n2.AddedOn, &n2.EditedOn, &n2.Body, &n2.Deleted, &n2.Dirty) |
| 246 | |
| 247 | // execute |
| 248 | tx, err := db.Begin() |
| 249 | if err != nil { |
| 250 | t.Fatal(errors.Wrap(err, "beginning a transaction for test case").Error()) |
| 251 | } |
| 252 | |
| 253 | if err := syncDeleteNote(tx, "n1-uuid"); err != nil { |
| 254 | tx.Rollback() |
| 255 | t.Fatal(errors.Wrap(err, "executing").Error()) |
| 256 | } |
| 257 | |
| 258 | tx.Commit() |
nothing calls this directly
no test coverage detected