(t *testing.T)
| 316 | } |
| 317 | |
| 318 | func TestNoteUpdateUUID(t *testing.T) { |
| 319 | testCases := []struct { |
| 320 | newUUID string |
| 321 | }{ |
| 322 | { |
| 323 | newUUID: "n1-new-uuid", |
| 324 | }, |
| 325 | { |
| 326 | newUUID: "n2-new-uuid", |
| 327 | }, |
| 328 | } |
| 329 | |
| 330 | for idx, tc := range testCases { |
| 331 | t.Run(fmt.Sprintf("testCase%d", idx), func(t *testing.T) { |
| 332 | // Setup |
| 333 | db := InitTestMemoryDB(t) |
| 334 | |
| 335 | n1 := Note{ |
| 336 | UUID: "n1-uuid", |
| 337 | BookUUID: "b1-uuid", |
| 338 | AddedOn: 1542058874, |
| 339 | Body: "n1-body", |
| 340 | USN: 1, |
| 341 | Deleted: true, |
| 342 | Dirty: false, |
| 343 | } |
| 344 | n2 := Note{ |
| 345 | UUID: "n2-uuid", |
| 346 | BookUUID: "b1-uuid", |
| 347 | AddedOn: 1542058874, |
| 348 | Body: "n2-body", |
| 349 | USN: 1, |
| 350 | Deleted: true, |
| 351 | Dirty: false, |
| 352 | } |
| 353 | |
| 354 | MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", n1.UUID, n1.BookUUID, n1.Body, n1.AddedOn, n1.USN, n1.Deleted, n1.Dirty) |
| 355 | MustExec(t, "inserting n2", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", n2.UUID, n2.BookUUID, n2.Body, n2.AddedOn, n2.USN, n2.Deleted, n2.Dirty) |
| 356 | |
| 357 | // execute |
| 358 | tx, err := db.Begin() |
| 359 | if err != nil { |
| 360 | t.Fatal(errors.Wrap(err, "beginning a transaction").Error()) |
| 361 | } |
| 362 | if err := n1.UpdateUUID(tx, tc.newUUID); err != nil { |
| 363 | tx.Rollback() |
| 364 | t.Fatal(errors.Wrap(err, "executing").Error()) |
| 365 | } |
| 366 | |
| 367 | tx.Commit() |
| 368 | |
| 369 | // test |
| 370 | var n1Record, n2Record Note |
| 371 | MustScan(t, "getting n1", |
| 372 | db.QueryRow("SELECT uuid, body, usn, deleted, dirty FROM notes WHERE body = ?", "n1-body"), |
| 373 | &n1Record.UUID, &n1Record.Body, &n1Record.USN, &n1Record.Deleted, &n1Record.Dirty) |
| 374 | MustScan(t, "getting n2", |
| 375 | db.QueryRow("SELECT uuid, body, usn, deleted, dirty FROM notes WHERE body = ?", "n2-body"), |
nothing calls this directly
no test coverage detected