-
Notifications
You must be signed in to change notification settings - Fork 26
/
is_empty_dir_test.go
70 lines (55 loc) · 1.33 KB
/
is_empty_dir_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package fs_test
import (
"os"
"path/filepath"
"testing"
"github.com/paketo-buildpacks/packit/v2/fs"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testIsEmptyDir(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
path string
)
it.Before(func() {
var err error
path, err = os.MkdirTemp("", "dir")
Expect(err).NotTo(HaveOccurred())
})
it.After(func() {
Expect(os.RemoveAll(path)).To(Succeed())
})
context("when the directory is empty", func() {
it("returns true", func() {
Expect(fs.IsEmptyDir(path)).To(BeTrue())
})
})
context("when the directory is not empty", func() {
it.Before(func() {
Expect(os.WriteFile(filepath.Join(path, "some-file"), []byte{}, 0644)).To(Succeed())
})
it("returns false", func() {
Expect(fs.IsEmptyDir(path)).To(BeFalse())
})
})
context("when the directory does not exist", func() {
it.Before(func() {
Expect(os.RemoveAll(path)).To(Succeed())
})
it("returns false", func() {
Expect(fs.IsEmptyDir(path)).To(BeFalse())
})
})
context("when the directory cannot be read", func() {
it.Before(func() {
Expect(os.Chmod(path, 0000)).To(Succeed())
})
it.After(func() {
Expect(os.Chmod(path, os.ModePerm)).To(Succeed())
})
it("returns false", func() {
Expect(fs.IsEmptyDir(path)).To(BeFalse())
})
})
}