util: Ensure the afero copy function is working as intended

The destination should be a dir sometimes.
This commit is contained in:
James Shubin
2019-07-22 06:38:02 -04:00
parent f94474e24f
commit 5d59cfd2c9
9 changed files with 77 additions and 0 deletions

View File

@@ -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) {
dir, err := TestDirFull()
if err != nil {