MCPcopy
hub / github.com/syncthing/syncthing / TestRemoveDirWithContent

Function TestRemoveDirWithContent

lib/model/model_test.go:2463–2521  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2461}
2462
2463func TestRemoveDirWithContent(t *testing.T) {
2464 m, conn, fcfg := setupModelWithConnection(t)
2465 tfs := fcfg.Filesystem()
2466 defer cleanupModelAndRemoveDir(m, tfs.URI())
2467
2468 tfs.MkdirAll("dirwith", 0o755)
2469 content := filepath.Join("dirwith", "content")
2470 fd, err := tfs.Create(content)
2471 must(t, err)
2472 fd.Close()
2473
2474 must(t, m.ScanFolder(fcfg.ID))
2475
2476 dir, ok := m.testCurrentFolderFile(fcfg.ID, "dirwith")
2477 if !ok {
2478 t.Fatalf("Can't get dir \"dirwith\" after initial scan")
2479 }
2480 dir.Deleted = true
2481 dir.Version = dir.Version.Update(device1.Short()).Update(device1.Short())
2482
2483 file, ok := m.testCurrentFolderFile(fcfg.ID, content)
2484 if !ok {
2485 t.Fatalf("Can't get file \"%v\" after initial scan", content)
2486 }
2487 file.Deleted = true
2488 file.Version = file.Version.Update(device1.Short()).Update(device1.Short())
2489
2490 must(t, m.IndexUpdate(conn, &protocol.IndexUpdate{Folder: fcfg.ID, Files: []protocol.FileInfo{dir, file}}))
2491
2492 // Is there something we could trigger on instead of just waiting?
2493 timeout := time.NewTimer(5 * time.Second)
2494 for {
2495 dir, ok := m.testCurrentFolderFile(fcfg.ID, "dirwith")
2496 if !ok {
2497 t.Fatalf("Can't get dir \"dirwith\" after index update")
2498 }
2499 file, ok := m.testCurrentFolderFile(fcfg.ID, content)
2500 if !ok {
2501 t.Fatalf("Can't get file \"%v\" after index update", content)
2502 }
2503 if dir.Deleted && file.Deleted {
2504 return
2505 }
2506
2507 select {
2508 case <-timeout.C:
2509 if !dir.Deleted && !file.Deleted {
2510 t.Errorf("Neither the dir nor its content was deleted before timing out.")
2511 } else if !dir.Deleted {
2512 t.Errorf("The dir was not deleted before timing out.")
2513 } else {
2514 t.Errorf("The content of the dir was not deleted before timing out.")
2515 }
2516 return
2517 default:
2518 time.Sleep(100 * time.Millisecond)
2519 }
2520 }

Callers

nothing calls this directly

Calls 13

setupModelWithConnectionFunction · 0.85
cleanupModelAndRemoveDirFunction · 0.85
mustFunction · 0.85
FilesystemMethod · 0.80
testCurrentFolderFileMethod · 0.80
ShortMethod · 0.80
URIMethod · 0.65
MkdirAllMethod · 0.65
CreateMethod · 0.65
CloseMethod · 0.65
ScanFolderMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected