-
Notifications
You must be signed in to change notification settings - Fork 11
/
utilities_test.go
83 lines (80 loc) · 2.04 KB
/
utilities_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
package main
import (
"reflect"
"testing"
)
func TestExclude(t *testing.T) {
t.Parallel()
tests := []struct {
name string
files []string
patterns []string
result []string
}{
{
name: "Empty",
files: []string{},
patterns: []string{},
result: []string{},
},
{
name: "No exclude pattern",
files: []string{"test.txt"},
patterns: []string{},
result: []string{"test.txt"},
},
{
name: "Folder with wildcard",
files: []string{"./1.txt", "./f/1.txt", "./f/2.txt"},
patterns: []string{"./f/*"},
result: []string{"./1.txt"},
},
{
name: "Nested folders with double star wildcard",
files: []string{"./f/f2/1.txt"},
patterns: []string{"./f/**"},
result: []string{},
},
{
name: "Exclude only nested folders with wildcard",
files: []string{"./f/f2/1.txt", "./f/f3/1.txt"},
patterns: []string{"./f/f2/*.txt"},
result: []string{"./f/f3/1.txt"},
},
{
name: "Files",
files: []string{"./1.txt", "./2.txt", "./f/1.txt", "./f/2.txt"},
patterns: []string{"./1.txt", "./f/1.txt"},
result: []string{"./2.txt", "./f/2.txt"},
},
{
name: "Files with wildcard",
files: []string{"./1.txt", "./2.txt", "./1.data"},
patterns: []string{"./*.txt"},
result: []string{"./1.data"},
},
{
name: "Relative path without .",
files: []string{"./1.txt", "2.txt", "./1.data", "2.data"},
patterns: []string{"*.txt"},
result: []string{"./1.data", "2.data"},
},
{
name: "Absolute paths",
files: []string{"/home/user/file.txt", "/home/user/file.data"},
patterns: []string{"/home/user/*.txt"},
result: []string{"/home/user/file.data"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := exclude(tt.files, tt.patterns)
if err != nil {
t.Errorf("exclude(%v, %v), got err: %v", tt.files, tt.patterns, err)
}
if !reflect.DeepEqual(got, tt.result) {
t.Errorf("exclude(%v, %v) = %v, want %v", tt.files, tt.patterns, got, tt.result)
}
})
}
}