MCPcopy
hub / github.com/pocketbase/pocketbase / TestMoveDirContent

Function TestMoveDirContent

tools/osutils/dir_test.go:14–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestMoveDirContent(t *testing.T) {
15 testDir := createTestDir(t)
16 defer os.RemoveAll(testDir)
17
18 exclude := []string{
19 "missing",
20 "test2",
21 "b",
22 }
23
24 // missing dest path
25 // ---
26 dir1 := filepath.Join(filepath.Dir(testDir), "a", "b", "c", "d", "_pb_move_dir_content_test_"+security.PseudorandomString(4))
27 defer os.RemoveAll(dir1)
28
29 if err := osutils.MoveDirContent(testDir, dir1, exclude...); err == nil {
30 t.Fatal("Expected path error, got nil")
31 }
32
33 // existing parent dir
34 // ---
35 dir2 := filepath.Join(filepath.Dir(testDir), "_pb_move_dir_content_test_"+security.PseudorandomString(4))
36 defer os.RemoveAll(dir2)
37
38 if err := osutils.MoveDirContent(testDir, dir2, exclude...); err != nil {
39 t.Fatalf("Expected dir2 to be created, got error: %v", err)
40 }
41
42 // find all files
43 files := []string{}
44 filepath.WalkDir(dir2, func(path string, d fs.DirEntry, err error) error {
45 if err != nil {
46 return err
47 }
48
49 if d.IsDir() {
50 return nil
51 }
52
53 files = append(files, path)
54
55 return nil
56 })
57
58 expectedFiles := []string{
59 filepath.Join(dir2, "test1"),
60 filepath.Join(dir2, "a", "a1"),
61 filepath.Join(dir2, "a", "a2"),
62 }
63
64 if len(files) != len(expectedFiles) {
65 t.Fatalf("Expected %d files, got %d: \n%v", len(expectedFiles), len(files), files)
66 }
67
68 for _, expected := range expectedFiles {
69 if !list.ExistInSlice(expected, files) {
70 t.Fatalf("Missing expected file %q in \n%v", expected, files)
71 }

Callers

nothing calls this directly

Calls 5

PseudorandomStringFunction · 0.92
MoveDirContentFunction · 0.92
ExistInSliceFunction · 0.92
createTestDirFunction · 0.70
RemoveAllMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…