Ver Fonte

graphtest: filter out lost+found dir entry

Ploop graph driver provides its own ext4 filesystem to every
container. It so happens that ext4 root comes with lost+found
directory, causing failures from DriverTestCreateEmpty() and
DriverTestCreateBase() tests on ploop.

While I am not yet ready to submit ploop graph driver for review,
this change looks simple enough to push.

Note that filtering is done without any additional allocations,
as described in https://github.com/golang/go/wiki/SliceTricks.

[v2: added a comment about lost+found]

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Kir Kolyshkin há 10 anos atrás
pai
commit
158c536267
1 ficheiros alterados com 21 adições e 2 exclusões
  1. 21 2
      daemon/graphdriver/graphtest/graphtest.go

+ 21 - 2
daemon/graphdriver/graphtest/graphtest.go

@@ -151,6 +151,25 @@ func verifyFile(t *testing.T, path string, mode os.FileMode, uid, gid uint32) {
 
 
 }
 }
 
 
+// readDir reads a directory just like ioutil.ReadDir()
+// then hides specific files (currently "lost+found")
+// so the tests don't "see" it
+func readDir(dir string) ([]os.FileInfo, error) {
+	a, err := ioutil.ReadDir(dir)
+	if err != nil {
+		return nil, err
+	}
+
+	b := a[:0]
+	for _, x := range a {
+		if x.Name() != "lost+found" { // ext4 always have this dir
+			b = append(b, x)
+		}
+	}
+
+	return b, nil
+}
+
 // DriverTestCreateEmpty creates an new image and verifies it is empty and the right metadata
 // DriverTestCreateEmpty creates an new image and verifies it is empty and the right metadata
 func DriverTestCreateEmpty(t *testing.T, drivername string) {
 func DriverTestCreateEmpty(t *testing.T, drivername string) {
 	driver := GetDriver(t, drivername)
 	driver := GetDriver(t, drivername)
@@ -172,7 +191,7 @@ func DriverTestCreateEmpty(t *testing.T, drivername string) {
 	verifyFile(t, dir, 0755|os.ModeDir, 0, 0)
 	verifyFile(t, dir, 0755|os.ModeDir, 0, 0)
 
 
 	// Verify that the directory is empty
 	// Verify that the directory is empty
-	fis, err := ioutil.ReadDir(dir)
+	fis, err := readDir(dir)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -231,7 +250,7 @@ func verifyBase(t *testing.T, driver graphdriver.Driver, name string) {
 	file := path.Join(dir, "a file")
 	file := path.Join(dir, "a file")
 	verifyFile(t, file, 0222|os.ModeSetuid, 0, 0)
 	verifyFile(t, file, 0222|os.ModeSetuid, 0, 0)
 
 
-	fis, err := ioutil.ReadDir(dir)
+	fis, err := readDir(dir)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}