TestInternalScan checks whether various fs operations are correctly represented in the db after scanning.
(t *testing.T)
| 2362 | // TestInternalScan checks whether various fs operations are correctly represented |
| 2363 | // in the db after scanning. |
| 2364 | func 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 |
nothing calls this directly
no test coverage detected