-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs-remove_test.go
143 lines (135 loc) Β· 3.64 KB
/
fs-remove_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package nef_test
import (
"errors"
"fmt"
"os"
"path/filepath"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ok
. "github.com/onsi/gomega" //nolint:revive // ok
nef "github.com/snivilised/nefilim"
lab "github.com/snivilised/nefilim/internal/laboratory"
"github.com/snivilised/nefilim/test/luna"
)
var _ = Describe("op: remove", Ordered, func() {
var (
root string
fS nef.UniversalFS
)
BeforeAll(func() {
root = luna.Repo("test")
})
BeforeEach(func() {
scratchPath := filepath.Join(root, lab.Static.FS.Scratch)
if _, err := os.Stat(scratchPath); err == nil {
Expect(os.RemoveAll(scratchPath)).To(Succeed(),
fmt.Sprintf("failed to delete existing directory %q", scratchPath),
)
}
})
DescribeTable("removal",
func(entry fsTE[nef.UniversalFS]) {
for _, overwrite := range []bool{false, true} {
fS = nef.NewUniversalFS(nef.Rel{
Root: root,
Overwrite: entry.overwrite,
})
Expect(fS.IsRelative()).To(BeTrue())
entry.overwrite = overwrite
if entry.arrange != nil {
entry.arrange(entry, fS)
}
entry.action(entry, fS)
}
},
func(entry fsTE[nef.UniversalFS]) string {
return fmt.Sprintf("π§ͺ ===> given: target is '%v', %v should: '%v'",
entry.given, entry.op, entry.should,
)
},
Entry(nil, fsTE[nef.UniversalFS]{
given: "file and exists",
should: "succeed",
op: "Remove",
require: lab.Static.FS.Scratch,
target: lab.Static.FS.Remove.File,
arrange: func(entry fsTE[nef.UniversalFS], _ nef.UniversalFS) {
err := require(root, entry.require, entry.target)
Expect(err).To(Succeed())
},
action: func(entry fsTE[nef.UniversalFS], fS nef.UniversalFS) {
if entry.overwrite {
// tbd
return
}
Expect(fS.Remove(entry.target)).To(Succeed())
},
}),
Entry(nil, fsTE[nef.UniversalFS]{
given: "path does not exist",
should: "fail",
op: "Remove",
require: lab.Static.FS.Scratch,
target: lab.Static.Foo,
action: func(entry fsTE[nef.UniversalFS], _ nef.UniversalFS) {
if entry.overwrite {
// tbd
return
}
Expect(fS.Remove(entry.target)).To(MatchError(os.ErrNotExist))
},
}),
Entry(nil, fsTE[nef.UniversalFS]{
given: "directory exists and not empty",
should: "fail",
op: "Remove",
require: lab.Static.FS.Scratch,
target: lab.Static.FS.Scratch,
arrange: func(entry fsTE[nef.UniversalFS], _ nef.UniversalFS) {
err := require(root, entry.require, lab.Static.FS.Remove.File)
Expect(err).To(Succeed())
},
action: func(entry fsTE[nef.UniversalFS], fS nef.UniversalFS) {
if entry.overwrite {
// tbd
return
}
Expect(errors.Unwrap(fS.Remove(entry.target))).To(
MatchError("directory not empty"),
)
},
}),
//
Entry(nil, fsTE[nef.UniversalFS]{
given: "path does not exist",
should: "succeed",
op: "RemoveAll",
require: lab.Static.FS.Scratch,
target: lab.Static.Foo,
action: func(entry fsTE[nef.UniversalFS], fS nef.UniversalFS) {
if entry.overwrite {
// tbd
return
}
Expect(fS.RemoveAll(entry.target)).To(Succeed())
},
}),
Entry(nil, fsTE[nef.UniversalFS]{
given: "directory exists and not empty",
should: "succeed",
op: "RemoveAll",
require: lab.Static.FS.Scratch,
target: lab.Static.FS.Scratch,
arrange: func(entry fsTE[nef.UniversalFS], _ nef.UniversalFS) {
err := require(root, entry.require, lab.Static.FS.Remove.File)
Expect(err).To(Succeed())
},
action: func(entry fsTE[nef.UniversalFS], _ nef.UniversalFS) {
if entry.overwrite {
// tbd
return
}
Expect(fS.RemoveAll(entry.target)).To(Succeed())
},
}),
)
})