2018-02-05 21:05:59 +00:00
|
|
|
package graphdriver // import "github.com/docker/docker/daemon/graphdriver"
|
2017-11-16 17:22:22 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
2017-11-16 17:22:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsEmptyDir(t *testing.T) {
|
2021-08-24 10:10:50 +00:00
|
|
|
tmp, err := os.MkdirTemp("", "test-is-empty-dir")
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-11-16 17:22:22 +00:00
|
|
|
defer os.RemoveAll(tmp)
|
|
|
|
|
|
|
|
d := filepath.Join(tmp, "empty-dir")
|
2022-01-20 12:59:20 +00:00
|
|
|
err = os.Mkdir(d, 0o755)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-11-16 17:22:22 +00:00
|
|
|
empty := isEmptyDir(d)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, empty)
|
2017-11-16 17:22:22 +00:00
|
|
|
|
|
|
|
d = filepath.Join(tmp, "dir-with-subdir")
|
2022-01-20 12:59:20 +00:00
|
|
|
err = os.MkdirAll(filepath.Join(d, "subdir"), 0o755)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2017-11-16 17:22:22 +00:00
|
|
|
empty = isEmptyDir(d)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, !empty)
|
2017-11-16 17:22:22 +00:00
|
|
|
|
|
|
|
d = filepath.Join(tmp, "dir-with-empty-file")
|
2022-01-20 12:59:20 +00:00
|
|
|
err = os.Mkdir(d, 0o755)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2022-05-31 15:01:43 +00:00
|
|
|
f, err := os.CreateTemp(d, "file")
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2022-05-31 15:01:43 +00:00
|
|
|
defer f.Close()
|
2017-11-16 17:22:22 +00:00
|
|
|
empty = isEmptyDir(d)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, !empty)
|
2017-11-16 17:22:22 +00:00
|
|
|
}
|