-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiter_test.go
68 lines (53 loc) · 1.55 KB
/
iter_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
package aferox_test
import (
"os"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/spf13/afero"
"github.com/unmango/aferox"
"github.com/unmango/go/slices"
)
var _ = Describe("Iter", func() {
It("should iterate over an empty fs", func() {
fs := afero.NewMemMapFs()
seq := aferox.Iter(fs, "")
a, b, c := slices.Collect3(seq)
Expect(a).To(ConsistOf("")) // root dir
Expect(b).To(HaveLen(1))
Expect(b[0].Name()).To(Equal(""))
Expect(c).To(ConsistOf(nil))
})
It("should skip root when iterating over an empty fs", func() {
fs := afero.NewMemMapFs()
seq := aferox.Iter(fs, "", aferox.SkipDirs)
a, b, c := slices.Collect3(seq)
Expect(a).To(BeEmpty())
Expect(b).To(BeEmpty())
Expect(c).To(BeEmpty())
})
It("should iterate over files", func() {
fs := afero.NewMemMapFs()
_, err := fs.Create("test.txt")
Expect(err).NotTo(HaveOccurred())
seq := aferox.Iter(fs, "")
a, b, c := slices.Collect3(seq)
Expect(a).To(ConsistOf("", "test.txt"))
Expect(b).To(HaveLen(2))
Expect(b[0].Name()).To(Equal(""))
Expect(b[1].Name()).To(Equal("test.txt"))
Expect(c).To(ConsistOf(nil, nil))
})
It("should iterate over directories", func() {
fs := afero.NewMemMapFs()
err := fs.Mkdir("test", os.ModeDir)
Expect(err).NotTo(HaveOccurred())
seq := aferox.Iter(fs, "")
a, b, c := slices.Collect3(seq)
Expect(a).To(ConsistOf("", "test"))
Expect(b).To(HaveLen(2))
Expect(b[0].Name()).To(Equal(""))
Expect(b[1].Name()).To(Equal("test"))
Expect(b[1].IsDir()).To(BeTrue())
Expect(c).To(ConsistOf(nil, nil))
})
})