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

Function TestBookUpdateUUID

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

Source from the content-addressed store, hash-verified

649}
650
651func TestBookUpdateUUID(t *testing.T) {
652 testCases := []struct {
653 newUUID string
654 }{
655 {
656 newUUID: "b1-new-uuid",
657 },
658 {
659 newUUID: "b2-new-uuid",
660 },
661 }
662
663 for idx, tc := range testCases {
664 t.Run(fmt.Sprintf("testCase%d", idx), func(t *testing.T) {
665
666 // Setup
667 db := InitTestMemoryDB(t)
668
669 b1 := Book{
670 UUID: "b1-uuid",
671 Label: "b1-label",
672 USN: 1,
673 Deleted: true,
674 Dirty: false,
675 }
676 b2 := Book{
677 UUID: "b2-uuid",
678 Label: "b2-label",
679 USN: 1,
680 Deleted: true,
681 Dirty: false,
682 }
683
684 MustExec(t, "inserting b1", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", b1.UUID, b1.Label, b1.USN, b1.Deleted, b1.Dirty)
685 MustExec(t, "inserting b2", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", b2.UUID, b2.Label, b2.USN, b2.Deleted, b2.Dirty)
686
687 // execute
688 tx, err := db.Begin()
689 if err != nil {
690 t.Fatal(errors.Wrap(err, "beginning a transaction").Error())
691 }
692 if err := b1.UpdateUUID(tx, tc.newUUID); err != nil {
693 tx.Rollback()
694 t.Fatal(errors.Wrap(err, "executing").Error())
695 }
696
697 tx.Commit()
698
699 // test
700 var b1Record, b2Record Book
701 MustScan(t, "getting b1",
702 db.QueryRow("SELECT uuid, label, usn, deleted, dirty FROM books WHERE label = ?", "b1-label"),
703 &b1Record.UUID, &b1Record.Label, &b1Record.USN, &b1Record.Deleted, &b1Record.Dirty)
704 MustScan(t, "getting b2",
705 db.QueryRow("SELECT uuid, label, usn, deleted, dirty FROM books WHERE label = ?", "b2-label"),
706 &b2Record.UUID, &b2Record.Label, &b2Record.USN, &b2Record.Deleted, &b2Record.Dirty)
707
708 assert.Equal(t, b1.UUID, tc.newUUID, "b1 original reference uuid mismatch")

Callers

nothing calls this directly

Calls 10

UpdateUUIDMethod · 0.95
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