util: Ensure the afero copy function is working as intended
The destination should be a dir sometimes.
This commit is contained in:
@@ -179,6 +179,70 @@ func TestCopyDiskToFs1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCopyDiskToFs2(t *testing.T) {
|
||||||
|
dir, err := TestDirFull()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("could not get tests directory: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Logf("tests directory is: %s", dir)
|
||||||
|
files, err := ioutil.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("could not read through tests directory: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sorted := []string{}
|
||||||
|
for _, f := range files {
|
||||||
|
if !f.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sorted = append(sorted, f.Name())
|
||||||
|
}
|
||||||
|
sort.Strings(sorted)
|
||||||
|
for _, f := range sorted {
|
||||||
|
treeFile := f + ".tree" // expected tree file
|
||||||
|
treeFileFull := dir + treeFile
|
||||||
|
info, err := os.Stat(treeFileFull)
|
||||||
|
if err != nil || info.IsDir() {
|
||||||
|
//t.Logf("skipping: %s -> %+v", treeFile, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
content, err := ioutil.ReadFile(treeFileFull)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("could not read tree file: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
str := string(content) // expected tree
|
||||||
|
|
||||||
|
t.Logf("testing: %s", treeFile)
|
||||||
|
|
||||||
|
mmFs := afero.NewMemMapFs()
|
||||||
|
afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil
|
||||||
|
fs := &Fs{afs}
|
||||||
|
|
||||||
|
src := dir + f + "/"
|
||||||
|
dst := "/dest/"
|
||||||
|
t.Logf("cp `%s` -> `%s`", src, dst)
|
||||||
|
if err := CopyDiskToFs(fs, src, dst, false); err != nil {
|
||||||
|
t.Errorf("copying to fs failed: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// this shows us what we pulled in from the test dir:
|
||||||
|
tree, err := FsTree(fs, "/")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("tree failed: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Logf("tree:\n%s", tree)
|
||||||
|
|
||||||
|
if tree != str {
|
||||||
|
t.Errorf("trees differ for: %s", treeFile)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCopyDiskContentsToFs1(t *testing.T) {
|
func TestCopyDiskContentsToFs1(t *testing.T) {
|
||||||
dir, err := TestDirFull()
|
dir, err := TestDirFull()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
13
util/afero_test/TestCopyDiskToFs2/simple1.tree
Normal file
13
util/afero_test/TestCopyDiskToFs2/simple1.tree
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
.
|
||||||
|
└── dest/
|
||||||
|
└── simple1/
|
||||||
|
├── 1
|
||||||
|
├── 2
|
||||||
|
├── 3
|
||||||
|
└── foo/
|
||||||
|
└── bar/
|
||||||
|
├── baz/
|
||||||
|
│ ├── a
|
||||||
|
│ ├── b
|
||||||
|
│ └── c
|
||||||
|
└── z
|
||||||
0
util/afero_test/TestCopyDiskToFs2/simple1/1
Normal file
0
util/afero_test/TestCopyDiskToFs2/simple1/1
Normal file
0
util/afero_test/TestCopyDiskToFs2/simple1/2
Normal file
0
util/afero_test/TestCopyDiskToFs2/simple1/2
Normal file
0
util/afero_test/TestCopyDiskToFs2/simple1/3
Normal file
0
util/afero_test/TestCopyDiskToFs2/simple1/3
Normal file
0
util/afero_test/TestCopyDiskToFs2/simple1/foo/bar/z
Normal file
0
util/afero_test/TestCopyDiskToFs2/simple1/foo/bar/z
Normal file
Reference in New Issue
Block a user