-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathremove_test.go
105 lines (87 loc) · 3.02 KB
/
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
package building
import (
"path/filepath"
"testing"
"gotest.tools/assert"
"gotest.tools/fs"
)
func TestRemove(t *testing.T) {
rootDirectory := fs.NewDir(t, "root",
fs.WithDir("empty-dir"),
fs.WithDir("full-dir",
fs.WithFile("some-file", "")),
fs.WithFile("file", ""),
fs.WithFile("remaining-file", ""),
fs.WithDir("remaining-dir"))
defer rootDirectory.Remove()
err := Remove{}.WithFiles(
filepath.Join(rootDirectory.Path(), "empty-dir"),
filepath.Join(rootDirectory.Path(), "full-dir"),
filepath.Join(rootDirectory.Path(), "non-existing"),
filepath.Join(rootDirectory.Path(), "file")).run()
assert.NilError(t, err)
expected := fs.Expected(t,
fs.WithFile("remaining-file", ""),
fs.WithDir("remaining-dir"))
assert.Assert(t, fs.Equal(rootDirectory.Path(), expected))
}
func TestRemoveWithFiles(t *testing.T) {
rootDirectory := fs.NewDir(t, "root",
fs.WithDir("empty-dir"),
fs.WithDir("full-dir",
fs.WithFile("some-file", "")),
fs.WithFile("remaining-file", ""))
defer rootDirectory.Remove()
err := Remove{}.WithFiles(
filepath.Join(rootDirectory.Path(), "*-dir"),
filepath.Join(rootDirectory.Path(), "full-dir")).run()
assert.NilError(t, err)
expected := fs.Expected(t, fs.WithFile("remaining-file", ""))
assert.Assert(t, fs.Equal(rootDirectory.Path(), expected))
}
func TestRemoveWithNonExistingFiles(t *testing.T) {
rootDirectory := fs.NewDir(t, "root",
fs.WithFile("remaining-file", ""))
defer rootDirectory.Remove()
err := Remove{}.WithFiles(
filepath.Join(rootDirectory.Path(), "non-existing*")).run()
assert.NilError(t, err)
expected := fs.Expected(t, fs.WithFile("remaining-file", ""))
assert.Assert(t, fs.Equal(rootDirectory.Path(), expected))
}
func TestRemoveWithFileset(t *testing.T) {
rootDirectory := fs.NewDir(t, "root",
fs.WithDir("empty-dir"),
fs.WithDir("full-dir",
fs.WithFile("some-file", "")),
fs.WithFile("remaining-file", ""))
defer rootDirectory.Remove()
err := Remove{}.WithFileset(rootDirectory.Path(), "*-dir,full-dir", "").run()
assert.NilError(t, err)
expected := fs.Expected(t, fs.WithFile("remaining-file", ""))
assert.Assert(t, fs.Equal(rootDirectory.Path(), expected))
}
func TestRemoveWithNonExistingFileset(t *testing.T) {
rootDirectory := fs.NewDir(t, "root",
fs.WithFile("remaining-file", ""))
defer rootDirectory.Remove()
err := Remove{}.WithFileset(rootDirectory.Path(), "non-existing*", "").run()
assert.NilError(t, err)
expected := fs.Expected(t, fs.WithFile("remaining-file", ""))
assert.Assert(t, fs.Equal(rootDirectory.Path(), expected))
}
func TestRemoveWithExcludes(t *testing.T) {
rootDirectory := fs.NewDir(t, "root",
fs.WithDir("empty-dir"),
fs.WithDir("full-dir",
fs.WithFile("some-file", "")),
fs.WithFile("remaining-file", ""))
defer rootDirectory.Remove()
err := Remove{}.WithFileset(rootDirectory.Path(), "*", "*-dir").run()
assert.NilError(t, err)
expected := fs.Expected(t,
fs.WithDir("empty-dir"),
fs.WithDir("full-dir",
fs.WithFile("some-file", "")))
assert.Assert(t, fs.Equal(rootDirectory.Path(), expected))
}