(t *testing.T)
| 3154 | } |
| 3155 | |
| 3156 | func 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 |
nothing calls this directly
no test coverage detected