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

Function TestBookExpunge

pkg/cli/database/models_test.go:715–766  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

713}
714
715func TestBookExpunge(t *testing.T) {
716 // Setup
717 db := InitTestMemoryDB(t)
718
719 b1 := Book{
720 UUID: "b1-uuid",
721 Label: "b1-label",
722 USN: 1,
723 Deleted: true,
724 Dirty: false,
725 }
726 b2 := Book{
727 UUID: "b2-uuid",
728 Label: "b2-label",
729 USN: 1,
730 Deleted: true,
731 Dirty: false,
732 }
733
734 MustExec(t, "inserting b1", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", b1.UUID, b1.Label, b1.USN, b1.Deleted, b1.Dirty)
735 MustExec(t, "inserting b2", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", b2.UUID, b2.Label, b2.USN, b2.Deleted, b2.Dirty)
736
737 // execute
738 tx, err := db.Begin()
739 if err != nil {
740 t.Fatal(errors.Wrap(err, "beginning a transaction").Error())
741 }
742
743 if err := b1.Expunge(tx); err != nil {
744 tx.Rollback()
745 t.Fatal(errors.Wrap(err, "executing").Error())
746 }
747
748 tx.Commit()
749
750 // test
751 var bookCount int
752 MustScan(t, "counting books", db.QueryRow("SELECT count(*) FROM books"), &bookCount)
753
754 assert.Equalf(t, bookCount, 1, "book count mismatch")
755
756 var b2Record Book
757 MustScan(t, "getting b2",
758 db.QueryRow("SELECT uuid, label, usn, deleted, dirty FROM books WHERE uuid = ?", "b2-uuid"),
759 &b2Record.UUID, &b2Record.Label, &b2Record.USN, &b2Record.Deleted, &b2Record.Dirty)
760
761 assert.Equal(t, b2Record.UUID, b2.UUID, "b2 uuid mismatch")
762 assert.Equal(t, b2Record.Label, b2.Label, "b2 label mismatch")
763 assert.Equal(t, b2Record.USN, b2.USN, "b2 usn mismatch")
764 assert.Equal(t, b2Record.Deleted, b2.Deleted, "b2 deleted mismatch")
765 assert.Equal(t, b2Record.Dirty, b2.Dirty, "b2 dirty mismatch")
766}
767
768// TestNoteFTS tests that note full text search indices stay in sync with the notes after insert, update and delete
769func TestNoteFTS(t *testing.T) {

Callers

nothing calls this directly

Calls 11

ExpungeMethod · 0.95
EqualfFunction · 0.92
EqualFunction · 0.92
InitTestMemoryDBFunction · 0.85
MustScanFunction · 0.85
MustExecFunction · 0.70
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
QueryRowMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected