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

Function TestBookInsert

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

Source from the content-addressed store, hash-verified

480}
481
482func TestBookInsert(t *testing.T) {
483 testCases := []struct {
484 uuid string
485 label string
486 usn int
487 deleted bool
488 dirty bool
489 }{
490 {
491 uuid: "b1-uuid",
492 label: "b1-label",
493 usn: 10808,
494 deleted: false,
495 dirty: false,
496 },
497 {
498 uuid: "b1-uuid",
499 label: "b1-label",
500 usn: 10808,
501 deleted: false,
502 dirty: true,
503 },
504 }
505
506 for idx, tc := range testCases {
507 func() {
508 // Setup
509 db := InitTestMemoryDB(t)
510
511 b := Book{
512 UUID: tc.uuid,
513 Label: tc.label,
514 USN: tc.usn,
515 Dirty: tc.dirty,
516 Deleted: tc.deleted,
517 }
518
519 // execute
520
521 tx, err := db.Begin()
522 if err != nil {
523 t.Fatal(errors.Wrap(err, fmt.Sprintf("beginning a transaction for test case %d", idx)).Error())
524 }
525
526 if err := b.Insert(tx); err != nil {
527 tx.Rollback()
528 t.Fatal(errors.Wrap(err, fmt.Sprintf("executing for test case %d", idx)).Error())
529 }
530
531 tx.Commit()
532
533 // test
534 var uuid, label string
535 var usn int
536 var deleted, dirty bool
537 MustScan(t, "getting b1",
538 db.QueryRow("SELECT uuid, label, usn, deleted, dirty FROM books WHERE uuid = ?", tc.uuid),
539 &uuid, &label, &usn, &deleted, &dirty)

Callers

nothing calls this directly

Calls 9

InsertMethod · 0.95
EqualFunction · 0.92
InitTestMemoryDBFunction · 0.85
MustScanFunction · 0.85
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
QueryRowMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected