Update diff apply test to check sub directories
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
parent
e306466569
commit
5c05b8447d
2 changed files with 27 additions and 3 deletions
|
@ -199,6 +199,7 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO
|
|||
upper := stringid.GenerateRandomID()
|
||||
deleteFile := "file-remove.txt"
|
||||
deleteFileContent := []byte("This file should get removed in upper!")
|
||||
deleteDir := "var/lib"
|
||||
|
||||
if err := driver.Create(base, "", "", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -212,6 +213,10 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := addDirectory(driver, base, deleteDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := driver.Create(upper, base, "", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -220,7 +225,7 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := removeFile(driver, upper, deleteFile); err != nil {
|
||||
if err := removeAll(driver, upper, deleteFile, deleteDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -271,6 +276,10 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO
|
|||
if err := checkFileRemoved(driver, diff, deleteFile); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := checkFileRemoved(driver, diff, deleteDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// DriverTestChanges tests computed changes on a layer matches changes made
|
||||
|
|
|
@ -78,14 +78,29 @@ func addFile(drv graphdriver.Driver, layer, filename string, content []byte) err
|
|||
return ioutil.WriteFile(path.Join(root, filename), content, 0755)
|
||||
}
|
||||
|
||||
func removeFile(drv graphdriver.Driver, layer, filename string) error {
|
||||
func addDirectory(drv graphdriver.Driver, layer, dir string) error {
|
||||
root, err := drv.Get(layer, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer drv.Put(layer)
|
||||
|
||||
return os.Remove(path.Join(root, filename))
|
||||
return os.MkdirAll(path.Join(root, dir), 0755)
|
||||
}
|
||||
|
||||
func removeAll(drv graphdriver.Driver, layer string, names ...string) error {
|
||||
root, err := drv.Get(layer, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer drv.Put(layer)
|
||||
|
||||
for _, filename := range names {
|
||||
if err := os.RemoveAll(path.Join(root, filename)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkFileRemoved(drv graphdriver.Driver, layer, filename string) error {
|
||||
|
|
Loading…
Reference in a new issue