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 (
|
|
|
|
"io/ioutil"
|
|
|
|
"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) {
|
|
|
|
tmp, err := ioutil.TempDir("", "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)
|
2017-11-16 12:22:22 -05:00
|
|
|
_, err = ioutil.TempFile(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
|
|
|
}
|