MCPcopy
hub / github.com/dnote/dnote / TestLocalMigration4

Function TestLocalMigration4

pkg/cli/migrate/migrate_test.go:545–584  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

543}
544
545func 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
586func TestLocalMigration5(t *testing.T) {
587 // set up

Callers

nothing calls this directly

Calls 11

InitTestMemoryDBRawFunction · 0.92
InitTestCtxWithDBFunction · 0.92
MustGenerateUUIDFunction · 0.92
MustExecFunction · 0.92
MustScanFunction · 0.92
EqualFunction · 0.92
NowMethod · 0.65
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected