MCPcopy
hub / github.com/syncthing/syncthing / TestCopierCleanup

Function TestCopierCleanup

lib/model/folder_sendrecv_test.go:312–343  ·  view source on GitHub ↗

Test that updating a file removes its old blocks from the blockmap

(t *testing.T)

Source from the content-addressed store, hash-verified

310
311// Test that updating a file removes its old blocks from the blockmap
312func TestCopierCleanup(t *testing.T) {
313 // Create a file
314 file := setupFile("test", []int{0})
315 file.Size = 1
316 m, f := setupSendReceiveFolder(t, file)
317
318 file.Blocks = []protocol.BlockInfo{blocks[1]}
319 file.Version = file.Version.Update(myID.Short())
320 // Update index (removing old blocks)
321 f.updateLocalsFromScanning([]protocol.FileInfo{file})
322
323 if vals, err := itererr.Collect(m.sdb.AllLocalBlocksWithHash(f.ID, blocks[0].Hash)); err != nil || len(vals) > 0 {
324 t.Error("Unexpected block found")
325 }
326
327 if vals, err := itererr.Collect(m.sdb.AllLocalBlocksWithHash(f.ID, blocks[1].Hash)); err != nil || len(vals) == 0 {
328 t.Error("Expected block not found")
329 }
330
331 file.Blocks = []protocol.BlockInfo{blocks[0]}
332 file.Version = file.Version.Update(myID.Short())
333 // Update index (removing old blocks)
334 f.updateLocalsFromScanning([]protocol.FileInfo{file})
335
336 if vals, err := itererr.Collect(m.sdb.AllLocalBlocksWithHash(f.ID, blocks[0].Hash)); err != nil || len(vals) == 0 {
337 t.Error("Unexpected block found")
338 }
339
340 if vals, err := itererr.Collect(m.sdb.AllLocalBlocksWithHash(f.ID, blocks[1].Hash)); err != nil || len(vals) > 0 {
341 t.Error("Expected block not found")
342 }
343}
344
345func TestDeregisterOnFailInCopy(t *testing.T) {
346 file := setupFile("filex", []int{0, 2, 0, 0, 5, 0, 0, 8})

Callers

nothing calls this directly

Calls 8

CollectFunction · 0.92
setupFileFunction · 0.85
setupSendReceiveFolderFunction · 0.85
ShortMethod · 0.80
UpdateMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected