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

Function TestCleanLocalNotes

pkg/cli/cmd/sync/sync_test.go:3085–3154  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3083}
3084
3085func TestCleanLocalNotes(t *testing.T) {
3086 // set up
3087 db := database.InitTestMemoryDB(t)
3088
3089 list := syncList{
3090 Notes: map[string]client.SyncFragNote{
3091 "n1-uuid": {
3092 UUID: "n1-uuid",
3093 },
3094 "n2-uuid": {
3095 UUID: "n2-uuid",
3096 },
3097 },
3098 Books: map[string]client.SyncFragBook{
3099 "b1-uuid": {
3100 UUID: "b1-uuid",
3101 },
3102 "b2-uuid": {
3103 UUID: "b2-uuid",
3104 },
3105 },
3106 ExpungedNotes: map[string]bool{
3107 "n3-uuid": true,
3108 "n4-uuid": true,
3109 },
3110 ExpungedBooks: map[string]bool{
3111 "b3-uuid": true,
3112 "b4-uuid": true,
3113 },
3114 MaxUSN: 1,
3115 MaxCurrentTime: 2,
3116 }
3117
3118 b1UUID := "b1-uuid"
3119 database.MustExec(t, "inserting b1", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", b1UUID, "b1-label", 1, false, false)
3120
3121 // exists in the list
3122 database.MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n1-uuid", b1UUID, 10, "n1 body", 1541108743, false, false)
3123 database.MustExec(t, "inserting n2", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n2-uuid", b1UUID, 0, "n2 body", 1541108743, false, true)
3124 // non-existent in the list but in valid state
3125 // (created in the cli and hasn't been uploaded)
3126 database.MustExec(t, "inserting n6", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n6-uuid", b1UUID, 0, "n6 body", 1541108743, false, true)
3127 // non-existent in the list and in an invalid state
3128 database.MustExec(t, "inserting n5", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n5-uuid", b1UUID, 7, "n5 body", 1541108743, true, true)
3129 database.MustExec(t, "inserting n9", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n9-uuid", b1UUID, 17, "n9 body", 1541108743, true, false)
3130 database.MustExec(t, "inserting n10", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n10-uuid", b1UUID, 0, "n10 body", 1541108743, false, false)
3131
3132 // execute
3133 tx, err := db.Begin()
3134 if err != nil {
3135 t.Fatal(errors.Wrap(err, "beginning a transaction").Error())
3136 }
3137
3138 if err := cleanLocalNotes(tx, &list); err != nil {
3139 tx.Rollback()
3140 t.Fatal(errors.Wrap(err, "executing").Error())
3141 }
3142

Callers

nothing calls this directly

Calls 10

InitTestMemoryDBFunction · 0.92
MustExecFunction · 0.92
MustScanFunction · 0.92
EqualFunction · 0.92
cleanLocalNotesFunction · 0.85
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
QueryRowMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected