MCPcopy Index your code
hub / github.com/dnote/dnote / TestLocalMigration9

Function TestLocalMigration9

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

Source from the content-addressed store, hash-verified

831}
832
833func TestLocalMigration9(t *testing.T) {
834 // set up
835 db := database.InitTestMemoryDBRaw(t, "./fixtures/local-9-pre-schema.sql")
836 ctx := context.InitTestCtxWithDB(t, db)
837
838 b1UUID := testutils.MustGenerateUUID(t)
839 database.MustExec(t, "inserting book 1", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", b1UUID, "b1")
840
841 n1UUID := testutils.MustGenerateUUID(t)
842 database.MustExec(t, "inserting n1", db, `INSERT INTO notes
843 (uuid, book_uuid, body, added_on, edited_on, public, dirty, usn, deleted) VALUES
844 (?, ?, ?, ?, ?, ?, ?, ?, ?)`, n1UUID, b1UUID, "n1 Body", 1, 2, true, true, 20, false)
845 n2UUID := testutils.MustGenerateUUID(t)
846 database.MustExec(t, "inserting n2", db, `INSERT INTO notes
847 (uuid, book_uuid, body, added_on, edited_on, public, dirty, usn, deleted) VALUES
848 (?, ?, ?, ?, ?, ?, ?, ?, ?)`, n2UUID, b1UUID, "n2 Body", 3, 4, false, true, 21, false)
849
850 // Execute
851 tx, err := db.Begin()
852 if err != nil {
853 t.Fatal(errors.Wrap(err, "beginning a transaction"))
854 }
855
856 err = lm9.run(ctx, tx)
857 if err != nil {
858 tx.Rollback()
859 t.Fatal(errors.Wrap(err, "failed to run"))
860 }
861
862 tx.Commit()
863
864 // Test
865
866 // assert that note_fts was populated with correct values
867 var noteFtsCount int
868 database.MustScan(t, "counting note_fts", db.QueryRow("SELECT count(*) FROM note_fts;"), &noteFtsCount)
869 assert.Equal(t, noteFtsCount, 2, "noteFtsCount mismatch")
870
871 var resCount int
872 database.MustScan(t, "counting result", db.QueryRow("SELECT count(*) FROM note_fts WHERE note_fts MATCH ?", "n1"), &resCount)
873 assert.Equal(t, resCount, 1, "noteFtsCount mismatch")
874}
875
876func TestLocalMigration10(t *testing.T) {
877 // set up

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected