Skip to content

Commit 15ecb92

Browse files
committed
add more test cases for scanDir func
1 parent 4dbec37 commit 15ecb92

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

scan_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ func TestScanDir(t *testing.T) {
2121
"regex_ignore/file6.txt": 600,
2222
"another_dir/file7.txt": 700,
2323
"symlink_target.txt": 800,
24+
"local.tmp": 0,
2425
}
2526

2627
dirs := []string{
2728
filepath.Join(tempDir, "subdir"),
2829
filepath.Join(tempDir, "regex_ignore"),
2930
filepath.Join(tempDir, "another_dir"),
3031
filepath.Join(tempDir, "empty_dir"),
32+
filepath.Join(tempDir, "ignore_dir"),
3133
}
3234

3335
for _, dir := range dirs {
@@ -76,6 +78,7 @@ func TestScanDir(t *testing.T) {
7678
ignoreNames: nil,
7779
ignoreRegex: nil,
7880
expectedSizes: map[int64]int{
81+
0: 1,
7982
100: 2, // two files of size 100
8083
200: 1,
8184
300: 1,
@@ -93,6 +96,7 @@ func TestScanDir(t *testing.T) {
9396
ignoreNames: map[string]struct{}{"ignored_file.txt": {}},
9497
ignoreRegex: nil,
9598
expectedSizes: map[int64]int{
99+
0: 1,
96100
100: 2,
97101
200: 1,
98102
400: 2,
@@ -108,6 +112,7 @@ func TestScanDir(t *testing.T) {
108112
ignoreNames: nil,
109113
ignoreRegex: regexp.MustCompile(`regex_ignore`),
110114
expectedSizes: map[int64]int{
115+
0: 1,
111116
100: 2,
112117
200: 1,
113118
300: 1,
@@ -124,6 +129,7 @@ func TestScanDir(t *testing.T) {
124129
ignoreNames: map[string]struct{}{"ignored_file.txt": {}},
125130
ignoreRegex: regexp.MustCompile(`regex_ignore`),
126131
expectedSizes: map[int64]int{
132+
0: 1,
127133
100: 2,
128134
200: 1,
129135
400: 2,
@@ -159,6 +165,41 @@ func TestScanDir(t *testing.T) {
159165
expectedSizes: map[int64]int{},
160166
expectError: false,
161167
},
168+
{
169+
name: "Ignore directory",
170+
root: tempDir,
171+
ignoreNames: map[string]struct{}{"ignore_dir": struct{}{}},
172+
ignoreRegex: nil,
173+
expectedSizes: map[int64]int{
174+
0: 1,
175+
100: 2,
176+
200: 1,
177+
300: 1,
178+
400: 2,
179+
500: 1,
180+
600: 1,
181+
700: 1,
182+
800: 1,
183+
},
184+
expectError: false,
185+
},
186+
{
187+
name: "Ignore file by regex",
188+
root: tempDir,
189+
ignoreNames: nil,
190+
ignoreRegex: regexp.MustCompile(`.*\.tmp$`),
191+
expectedSizes: map[int64]int{
192+
100: 2,
193+
200: 1,
194+
300: 1,
195+
400: 2,
196+
500: 1,
197+
600: 1,
198+
700: 1,
199+
800: 1,
200+
},
201+
expectError: false,
202+
},
162203
}
163204

164205
for _, tc := range tests {

0 commit comments

Comments
 (0)