(t *testing.T)
| 543 | } |
| 544 | |
| 545 | func TestLocalMigration4(t *testing.T) { |
| 546 | // set up |
| 547 | db := database.InitTestMemoryDBRaw(t, "./fixtures/local-1-pre-schema.sql") |
| 548 | ctx := context.InitTestCtxWithDB(t, db) |
| 549 | |
| 550 | b1UUID := testutils.MustGenerateUUID(t) |
| 551 | database.MustExec(t, "inserting css book", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", b1UUID, "css") |
| 552 | n1UUID := testutils.MustGenerateUUID(t) |
| 553 | database.MustExec(t, "inserting css note", db, "INSERT INTO notes (uuid, book_uuid, content, added_on) VALUES (?, ?, ?, ?)", n1UUID, b1UUID, "n1 content", time.Now().UnixNano()) |
| 554 | |
| 555 | // Execute |
| 556 | tx, err := db.Begin() |
| 557 | if err != nil { |
| 558 | t.Fatal(errors.Wrap(err, "beginning a transaction")) |
| 559 | } |
| 560 | |
| 561 | err = lm4.run(ctx, tx) |
| 562 | if err != nil { |
| 563 | tx.Rollback() |
| 564 | t.Fatal(errors.Wrap(err, "failed to run")) |
| 565 | } |
| 566 | |
| 567 | tx.Commit() |
| 568 | |
| 569 | // Test |
| 570 | var n1Dirty, b1Dirty bool |
| 571 | var n1Deleted, b1Deleted bool |
| 572 | var n1USN, b1USN int |
| 573 | database.MustScan(t, "scanning the newly added dirty flag of n1", db.QueryRow("SELECT dirty, deleted, usn FROM notes WHERE uuid = ?", n1UUID), &n1Dirty, &n1Deleted, &n1USN) |
| 574 | database.MustScan(t, "scanning the newly added dirty flag of b1", db.QueryRow("SELECT dirty, deleted, usn FROM books WHERE uuid = ?", b1UUID), &b1Dirty, &b1Deleted, &b1USN) |
| 575 | |
| 576 | assert.Equal(t, n1Dirty, false, "n1 dirty flag should be false by default") |
| 577 | assert.Equal(t, b1Dirty, false, "b1 dirty flag should be false by default") |
| 578 | |
| 579 | assert.Equal(t, n1Deleted, false, "n1 deleted flag should be false by default") |
| 580 | assert.Equal(t, b1Deleted, false, "b1 deleted flag should be false by default") |
| 581 | |
| 582 | assert.Equal(t, n1USN, 0, "n1 usn flag should be 0 by default") |
| 583 | assert.Equal(t, b1USN, 0, "b1 usn flag should be 0 by default") |
| 584 | } |
| 585 | |
| 586 | func TestLocalMigration5(t *testing.T) { |
| 587 | // set up |
nothing calls this directly
no test coverage detected