| 71 | } |
| 72 | |
| 73 | func TestNoteInsert(t *testing.T) { |
| 74 | testCases := []struct { |
| 75 | uuid string |
| 76 | bookUUID string |
| 77 | body string |
| 78 | addedOn int64 |
| 79 | editedOn int64 |
| 80 | usn int |
| 81 | deleted bool |
| 82 | dirty bool |
| 83 | }{ |
| 84 | { |
| 85 | uuid: "n1-uuid", |
| 86 | bookUUID: "b1-uuid", |
| 87 | body: "n1-body", |
| 88 | addedOn: 1542058875, |
| 89 | editedOn: 0, |
| 90 | usn: 0, |
| 91 | deleted: false, |
| 92 | dirty: false, |
| 93 | }, |
| 94 | { |
| 95 | uuid: "n2-uuid", |
| 96 | bookUUID: "b2-uuid", |
| 97 | body: "n2-body", |
| 98 | addedOn: 1542058875, |
| 99 | editedOn: 1542058876, |
| 100 | usn: 1008, |
| 101 | deleted: true, |
| 102 | dirty: true, |
| 103 | }, |
| 104 | } |
| 105 | |
| 106 | for idx, tc := range testCases { |
| 107 | func() { |
| 108 | // Setup |
| 109 | db := InitTestMemoryDB(t) |
| 110 | |
| 111 | n := Note{ |
| 112 | UUID: tc.uuid, |
| 113 | BookUUID: tc.bookUUID, |
| 114 | Body: tc.body, |
| 115 | AddedOn: tc.addedOn, |
| 116 | EditedOn: tc.editedOn, |
| 117 | USN: tc.usn, |
| 118 | Deleted: tc.deleted, |
| 119 | Dirty: tc.dirty, |
| 120 | } |
| 121 | |
| 122 | // execute |
| 123 | tx, err := db.Begin() |
| 124 | if err != nil { |
| 125 | t.Fatal(errors.Wrap(err, fmt.Sprintf("beginning a transaction for test case %d", idx)).Error()) |
| 126 | } |
| 127 | |
| 128 | if err := n.Insert(tx); err != nil { |
| 129 | tx.Rollback() |
| 130 | t.Fatal(errors.Wrap(err, fmt.Sprintf("executing for test case %d", idx)).Error()) |