(t *testing.T)
| 649 | } |
| 650 | |
| 651 | func 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") |
nothing calls this directly
no test coverage detected