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

Function TestCleanLocalBooks

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

Source from the content-addressed store, hash-verified

3154}
3155
3156func TestCleanLocalBooks(t *testing.T) {
3157 // set up
3158 db := database.InitTestMemoryDB(t)
3159
3160 list := syncList{
3161 Notes: map[string]client.SyncFragNote{
3162 "n1-uuid": {
3163 UUID: "n1-uuid",
3164 },
3165 "n2-uuid": {
3166 UUID: "n2-uuid",
3167 },
3168 },
3169 Books: map[string]client.SyncFragBook{
3170 "b1-uuid": {
3171 UUID: "b1-uuid",
3172 },
3173 "b2-uuid": {
3174 UUID: "b2-uuid",
3175 },
3176 },
3177 ExpungedNotes: map[string]bool{
3178 "n3-uuid": true,
3179 "n4-uuid": true,
3180 },
3181 ExpungedBooks: map[string]bool{
3182 "b3-uuid": true,
3183 "b4-uuid": true,
3184 },
3185 MaxUSN: 1,
3186 MaxCurrentTime: 2,
3187 }
3188
3189 // existent in the server
3190 database.MustExec(t, "inserting b1", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", "b1-uuid", "b1-label", 1, false, false)
3191 database.MustExec(t, "inserting b3", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", "b3-uuid", "b3-label", 0, false, true)
3192 // non-existent in the server but in valid state
3193 database.MustExec(t, "inserting b5", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", "b5-uuid", "b5-label", 0, true, true)
3194 // non-existent in the server and in an invalid state
3195 database.MustExec(t, "inserting b6", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", "b6-uuid", "b6-label", 10, true, true)
3196 database.MustExec(t, "inserting b7", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", "b7-uuid", "b7-label", 11, false, false)
3197 database.MustExec(t, "inserting b8", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", "b8-uuid", "b8-label", 0, false, false)
3198
3199 // execute
3200 tx, err := db.Begin()
3201 if err != nil {
3202 t.Fatal(errors.Wrap(err, "beginning a transaction").Error())
3203 }
3204
3205 if err := cleanLocalBooks(tx, &list); err != nil {
3206 tx.Rollback()
3207 t.Fatal(errors.Wrap(err, "executing").Error())
3208 }
3209
3210 tx.Commit()
3211
3212 // test
3213 var bookCount int

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected