-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs-rename_test.go
270 lines (251 loc) Β· 9.84 KB
/
fs-rename_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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
package nef_test
import (
"fmt"
. "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: rename", Ordered, func() {
var (
root string
fS nef.RenameFS
)
BeforeAll(func() {
root = luna.Repo("test")
})
BeforeEach(func() {
fS = nef.NewUniversalFS(nef.Rel{
Root: root,
Overwrite: false,
})
scratch(root)
})
DescribeTable("fs: RenameFS",
func(entry fsTE[nef.RenameFS]) {
if entry.arrange != nil {
entry.arrange(entry, fS)
}
entry.action(entry, fS)
},
func(entry fsTE[nef.RenameFS]) string {
return fmt.Sprintf("π§ͺ ===> given: target is '%v', %v should: '%v'",
entry.given, entry.op, entry.should,
)
},
// The following tests are a duplicate of those defined for the move
// operation π, but with appropriately adjusted expectations.
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] file exists, [to] directory exists, [no-clash]",
should: "fail, because filename is missing, from to path",
note: "filename not included in the destination path (from/file.txt => to)",
op: "Rename",
require: lab.Static.FS.Scratch,
from: lab.Static.FS.Move.From.File,
to: lab.Static.FS.Scratch,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require, entry.from)).To(Succeed())
Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
luna.IsLinkError(fS.Rename(entry.from, lab.Static.FS.Move.Destination), entry.should)
},
}),
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] file exists, [to] directory exists, [clash]",
should: "succeed, only if override",
note: "filename not included in the destination path (from/file.txt => to)",
op: "Move",
require: lab.Static.FS.Scratch,
from: lab.Static.FS.Move.From.File,
to: lab.Static.FS.Scratch,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root,
entry.require,
entry.from,
)).To(Succeed())
Expect(require(root,
lab.Static.FS.Move.Destination,
lab.Static.FS.Move.To.File,
)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
luna.IsLinkError(fS.Rename(entry.from, lab.Static.FS.Move.Destination), entry.should)
},
}),
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] file exists, [to] directory exists, [no-clash]",
should: "succeed",
note: "filename IS included in the destination path (from/file.txt => to/file.txt)",
op: "Move",
require: lab.Static.FS.Scratch,
from: lab.Static.FS.Move.From.File,
to: lab.Static.FS.Scratch,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require, entry.from)).To(Succeed())
Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
destination := lab.Static.FS.Move.To.File
Expect(fS.Rename(entry.from, destination)).To(Succeed())
Expect(luna.AsFile(destination)).To(luna.ExistInFS(fS))
},
}),
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] file exists, [to] directory exists, [clash]",
should: "succeed; move and overwrite",
note: "filename IS included in the destination path (from/file.txt => to/file.txt)",
op: "Move",
require: lab.Static.FS.Scratch,
from: lab.Static.FS.Move.From.File,
to: lab.Static.FS.Scratch,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require, entry.from)).To(Succeed())
if entry.overwrite {
Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed())
return
}
Expect(require(root,
lab.Static.FS.Move.Destination,
lab.Static.FS.Move.To.File,
)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
Expect(fS.Rename(entry.from, lab.Static.FS.Move.To.File)).To(Succeed())
Expect(luna.AsFile(lab.Static.FS.Move.From.File)).NotTo(luna.ExistInFS(fS))
},
}),
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] directory exists, [to] directory exists, [no clash]",
should: "fail, because dir name is missing, from to path",
note: "directory not included in the destination path (from/dir => to)",
op: "Move",
require: lab.Static.FS.Move.From.Directory,
from: lab.Static.FS.Move.From.Directory,
to: lab.Static.FS.Scratch,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require)).To(Succeed())
Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
luna.IsLinkError(fS.Rename(entry.from, lab.Static.FS.Move.Destination), entry.should)
},
}),
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] directory exists, [to] directory exists, [clash]",
should: "fail",
note: "directory not included in the destination path (from/dir => to)",
op: "Move",
require: lab.Static.FS.Move.From.Directory,
from: lab.Static.FS.Move.From.Directory,
to: lab.Static.FS.Scratch,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require)).To(Succeed())
Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed())
Expect(require(root, lab.Static.FS.Move.To.Directory)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
luna.IsLinkError(fS.Rename(entry.from, lab.Static.FS.Move.Destination), entry.should)
Expect(luna.AsDirectory(lab.Static.FS.Move.From.Directory)).To(luna.ExistInFS(fS))
},
}),
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] directory exists, [to] directory exists, [no clash]",
should: "succeed",
note: "directory IS included in the destination path (from/dir => to/dir)",
op: "Move",
require: lab.Static.FS.Move.From.Directory,
from: lab.Static.FS.Move.From.Directory,
to: lab.Static.FS.Scratch,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require)).To(Succeed())
Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
destination := lab.Static.FS.Move.To.Directory
Expect(fS.Rename(entry.from, destination)).To(Succeed())
Expect(luna.AsDirectory(destination)).To(luna.ExistInFS(fS))
},
}),
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] directory exists, [to] directory exists, [clash]",
should: "fail",
note: "directory IS included in the destination path (from/dir => to/dir)",
op: "Move",
require: lab.Static.FS.Move.From.Directory,
from: lab.Static.FS.Move.From.Directory,
to: lab.Static.FS.Scratch,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require)).To(Succeed())
Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed())
Expect(require(root, lab.Static.FS.Move.To.Directory)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
destination := lab.Static.FS.Move.To.Directory
Expect(fS.Rename(entry.from, destination)).NotTo(Succeed())
Expect(luna.AsDirectory(lab.Static.FS.Move.From.Directory)).To(luna.ExistInFS(fS))
},
}),
// π The tests in the follow section are defined for scenarios where the
// target item is being renamed into the same directory; ie it is a rename,
// without moving to a different directory.
//
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] file exists, [to] name does not exist, [no-clash]",
should: "succeed",
op: "Rename",
require: lab.Static.FS.Scratch,
from: lab.Static.FS.Rename.From.File,
to: lab.Static.FS.Rename.To.File,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require, entry.from)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
Expect(fS.Rename(entry.from, entry.to)).To(Succeed())
},
}),
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] file exists, [to] equal to [from], [clash]",
should: "succeed, ignored",
op: "Rename",
require: lab.Static.FS.Scratch,
from: lab.Static.FS.Rename.From.File,
to: lab.Static.FS.Rename.From.File,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require, entry.from)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
Expect(fS.Rename(entry.from, entry.to)).To(Succeed())
},
}),
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] directory exists, [to] name does not exist, [no-clash]",
should: "succeed",
op: "Rename",
require: lab.Static.FS.Rename.From.Directory,
from: lab.Static.FS.Rename.From.Directory,
to: lab.Static.FS.Rename.To.Directory,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
Expect(fS.Rename(entry.from, entry.to)).To(Succeed())
},
}),
Entry(nil, fsTE[nef.RenameFS]{
given: "[from] directory exists, [to] equal to [from], [clash]",
should: "fail, directory names can't be same",
op: "Rename",
require: lab.Static.FS.Rename.From.Directory,
from: lab.Static.FS.Rename.From.Directory,
to: lab.Static.FS.Rename.From.Directory,
arrange: func(entry fsTE[nef.RenameFS], _ nef.RenameFS) {
Expect(require(root, entry.require)).To(Succeed())
},
action: func(entry fsTE[nef.RenameFS], fS nef.RenameFS) {
luna.IsLinkError(fS.Rename(entry.from, entry.to), entry.should)
},
}),
)
})