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

Function TestNoteExpunge

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

Source from the content-addressed store, hash-verified

383}
384
385func TestNoteExpunge(t *testing.T) {
386 // Setup
387 db := InitTestMemoryDB(t)
388
389 n1 := Note{
390 UUID: "n1-uuid",
391 BookUUID: "b9-uuid",
392 Body: "n1 body",
393 AddedOn: 1542058874,
394 EditedOn: 0,
395 USN: 22,
396 Deleted: false,
397 Dirty: false,
398 }
399 n2 := Note{
400 UUID: "n2-uuid",
401 BookUUID: "b10-uuid",
402 Body: "n2 body",
403 AddedOn: 1542058875,
404 EditedOn: 0,
405 USN: 39,
406 Deleted: false,
407 Dirty: false,
408 }
409
410 MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, usn, added_on, edited_on, body, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", n1.UUID, n1.BookUUID, n1.USN, n1.AddedOn, n1.EditedOn, n1.Body, n1.Deleted, n1.Dirty)
411 MustExec(t, "inserting n2", db, "INSERT INTO notes (uuid, book_uuid, usn, added_on, edited_on, body, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", n2.UUID, n2.BookUUID, n2.USN, n2.AddedOn, n2.EditedOn, n2.Body, n2.Deleted, n2.Dirty)
412
413 // execute
414 tx, err := db.Begin()
415 if err != nil {
416 t.Fatal(errors.Wrap(err, "beginning a transaction").Error())
417 }
418
419 if err := n1.Expunge(tx); err != nil {
420 tx.Rollback()
421 t.Fatal(errors.Wrap(err, "executing").Error())
422 }
423
424 tx.Commit()
425
426 // test
427 var noteCount int
428 MustScan(t, "counting notes", db.QueryRow("SELECT count(*) FROM notes"), &noteCount)
429
430 assert.Equalf(t, noteCount, 1, "note count mismatch")
431
432 var n2Record Note
433 MustScan(t, "getting n2",
434 db.QueryRow("SELECT uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty FROM notes WHERE uuid = ?", n2.UUID),
435 &n2Record.UUID, &n2Record.BookUUID, &n2Record.Body, &n2Record.AddedOn, &n2Record.EditedOn, &n2Record.USN, &n2Record.Deleted, &n2Record.Dirty)
436
437 assert.Equal(t, n2Record.UUID, n2.UUID, "n2 uuid mismatch")
438 assert.Equal(t, n2Record.BookUUID, n2.BookUUID, "n2 bookUUID mismatch")
439 assert.Equal(t, n2Record.Body, n2.Body, "n2 body mismatch")
440 assert.Equal(t, n2Record.AddedOn, n2.AddedOn, "n2 addedOn mismatch")
441 assert.Equal(t, n2Record.EditedOn, n2.EditedOn, "n2 editedOn mismatch")
442 assert.Equal(t, n2Record.USN, n2.USN, "n2 usn mismatch")

Callers

nothing calls this directly

Calls 11

ExpungeMethod · 0.95
EqualfFunction · 0.92
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