Update diff apply test to check sub directories

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
(cherry picked from commit 5c05b8447d)
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Derek McGowan 2016-07-26 11:56:38 -07:00 committed by Tibor Vass
parent 0a4abdb0ac
commit b49dd20939
2 changed files with 27 additions and 3 deletions

View file

@ -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

View file

@ -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 {