(t *testing.T)
| 351 | } |
| 352 | |
| 353 | func TestSyncDeleteBook(t *testing.T) { |
| 354 | t.Run("exists on server only", func(t *testing.T) { |
| 355 | // set up |
| 356 | db := database.InitTestMemoryDB(t) |
| 357 | database.MustExec(t, "inserting b1 for test case %d", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", "b1-uuid", "b1-label") |
| 358 | |
| 359 | var b1 database.Book |
| 360 | database.MustScan(t, "getting b1 for test case", |
| 361 | db.QueryRow("SELECT uuid, label, usn, dirty FROM books WHERE uuid = ?", "b1-uuid"), |
| 362 | &b1.UUID, &b1.Label, &b1.USN, &b1.Dirty) |
| 363 | |
| 364 | // execute |
| 365 | tx, err := db.Begin() |
| 366 | if err != nil { |
| 367 | t.Fatal(errors.Wrap(err, "beginning a transaction").Error()) |
| 368 | } |
| 369 | |
| 370 | if err := syncDeleteBook(tx, "nonexistent-book-uuid"); err != nil { |
| 371 | tx.Rollback() |
| 372 | t.Fatal(errors.Wrap(err, "executing").Error()) |
| 373 | } |
| 374 | |
| 375 | tx.Commit() |
| 376 | |
| 377 | // test |
| 378 | var noteCount, bookCount int |
| 379 | database.MustScan(t, "counting notes", db.QueryRow("SELECT count(*) FROM notes"), ¬eCount) |
| 380 | database.MustScan(t, "counting books", db.QueryRow("SELECT count(*) FROM books"), &bookCount) |
| 381 | |
| 382 | assert.Equalf(t, noteCount, 0, "note count mismatch") |
| 383 | assert.Equalf(t, bookCount, 1, "book count mismatch") |
| 384 | |
| 385 | var b1Record database.Book |
| 386 | database.MustScan(t, "getting b1 for test case", |
| 387 | db.QueryRow("SELECT uuid, label, usn, dirty FROM books WHERE uuid = ?", "b1-uuid"), |
| 388 | &b1Record.UUID, &b1Record.Label, &b1Record.USN, &b1Record.Dirty) |
| 389 | |
| 390 | assert.Equal(t, b1Record.UUID, b1.UUID, "b1 UUID mismatch for test case") |
| 391 | assert.Equal(t, b1Record.Label, b1.Label, "b1 Label mismatch for test case") |
| 392 | assert.Equal(t, b1Record.USN, b1.USN, "b1 USN mismatch for test case") |
| 393 | assert.Equal(t, b1Record.Dirty, b1.Dirty, "b1 Dirty mismatch for test case") |
| 394 | }) |
| 395 | |
| 396 | t.Run("local copy is dirty", func(t *testing.T) { |
| 397 | b1UUID := testutils.MustGenerateUUID(t) |
| 398 | |
| 399 | // set up |
| 400 | db := database.InitTestMemoryDB(t) |
| 401 | |
| 402 | database.MustExec(t, "inserting b1 for test case %d", db, "INSERT INTO books (uuid, label, usn, dirty) VALUES (?, ?, ?, ?)", b1UUID, "b1-label", 12, true) |
| 403 | 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) |
| 404 | |
| 405 | var b1 database.Book |
| 406 | database.MustScan(t, "getting b1 for test case", |
| 407 | db.QueryRow("SELECT uuid, label, usn, dirty FROM books WHERE uuid = ?", b1UUID), |
| 408 | &b1.UUID, &b1.Label, &b1.USN, &b1.Dirty) |
| 409 | var n1 database.Note |
| 410 | database.MustScan(t, "getting n1 for test case", |
nothing calls this directly
no test coverage detected