MCPcopy
hub / github.com/syncthing/syncthing / TestInternalScan

Function TestInternalScan

lib/model/model_test.go:2364–2420  ·  view source on GitHub ↗

TestInternalScan checks whether various fs operations are correctly represented in the db after scanning.

(t *testing.T)

Source from the content-addressed store, hash-verified

2362// TestInternalScan checks whether various fs operations are correctly represented
2363// in the db after scanning.
2364func TestInternalScan(t *testing.T) {
2365 w, fcfg := newDefaultCfgWrapper(t)
2366 testFs := fcfg.Filesystem()
2367 defer os.RemoveAll(testFs.URI())
2368
2369 testCases := map[string]func(protocol.FileInfo) bool{
2370 "removeDir": func(f protocol.FileInfo) bool {
2371 return !f.Deleted
2372 },
2373 "dirToFile": func(f protocol.FileInfo) bool {
2374 return f.Deleted || f.IsDirectory()
2375 },
2376 }
2377
2378 baseDirs := []string{"dirToFile", "removeDir"}
2379 for _, dir := range baseDirs {
2380 sub := filepath.Join(dir, "subDir")
2381 for _, dir := range []string{dir, sub} {
2382 if err := testFs.MkdirAll(dir, 0o775); err != nil {
2383 t.Fatalf("%v: %v", dir, err)
2384 }
2385 }
2386 testCases[sub] = func(f protocol.FileInfo) bool {
2387 return !f.Deleted
2388 }
2389 for _, dir := range []string{dir, sub} {
2390 file := filepath.Join(dir, "a")
2391 fd, err := testFs.Create(file)
2392 must(t, err)
2393 fd.Close()
2394 testCases[file] = func(f protocol.FileInfo) bool {
2395 return !f.Deleted
2396 }
2397 }
2398 }
2399
2400 m := setupModel(t, w)
2401 defer cleanupModel(m)
2402
2403 for _, dir := range baseDirs {
2404 must(t, testFs.RemoveAll(dir))
2405 }
2406
2407 fd, err := testFs.Create("dirToFile")
2408 must(t, err)
2409 fd.Close()
2410
2411 m.ScanFolder("default")
2412
2413 for path, cond := range testCases {
2414 if f, ok := m.testCurrentFolderFile("default", path); !ok {
2415 t.Fatalf("%v missing in db", path)
2416 } else if cond(f) {
2417 t.Errorf("Incorrect db entry for %v", path)
2418 }
2419 }
2420}
2421

Callers

nothing calls this directly

Calls 13

newDefaultCfgWrapperFunction · 0.85
mustFunction · 0.85
setupModelFunction · 0.85
cleanupModelFunction · 0.85
FilesystemMethod · 0.80
testCurrentFolderFileMethod · 0.80
RemoveAllMethod · 0.65
URIMethod · 0.65
MkdirAllMethod · 0.65
CreateMethod · 0.65
CloseMethod · 0.65
ScanFolderMethod · 0.65

Tested by

no test coverage detected