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