github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/daemon/graphdriver/driver_test.go (about) 1 package graphdriver // import "github.com/demonoid81/moby/daemon/graphdriver" 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "testing" 8 9 "gotest.tools/v3/assert" 10 ) 11 12 func TestIsEmptyDir(t *testing.T) { 13 tmp, err := ioutil.TempDir("", "test-is-empty-dir") 14 assert.NilError(t, err) 15 defer os.RemoveAll(tmp) 16 17 d := filepath.Join(tmp, "empty-dir") 18 err = os.Mkdir(d, 0755) 19 assert.NilError(t, err) 20 empty := isEmptyDir(d) 21 assert.Check(t, empty) 22 23 d = filepath.Join(tmp, "dir-with-subdir") 24 err = os.MkdirAll(filepath.Join(d, "subdir"), 0755) 25 assert.NilError(t, err) 26 empty = isEmptyDir(d) 27 assert.Check(t, !empty) 28 29 d = filepath.Join(tmp, "dir-with-empty-file") 30 err = os.Mkdir(d, 0755) 31 assert.NilError(t, err) 32 _, err = ioutil.TempFile(d, "file") 33 assert.NilError(t, err) 34 empty = isEmptyDir(d) 35 assert.Check(t, !empty) 36 }