-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatch_names_test.go
87 lines (77 loc) · 1.72 KB
/
match_names_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
package recurparse
import (
"fmt"
"os"
"path/filepath"
"runtime"
"testing"
)
func TestMatchingNames(t *testing.T) {
type matchingNamesDatum struct {
Directory string
Glob string
Expected []string
ExpectedErr string
}
matchingNamesData := []matchingNamesDatum{
{
Directory: "testdata/getFiles/1_simple_flat",
Glob: "*.html",
Expected: []string{
"1.html",
"3.html",
},
},
{
Directory: "testdata/getFiles/2_simple_dirs",
Glob: "*.html",
Expected: []string{
"1.html",
"3.html",
"first/4.html",
"second/7.html",
},
},
}
if runtime.GOOS != "windows" {
matchingNamesData = append(matchingNamesData, matchingNamesDatum{
Directory: "testdata/getFiles/3_unix_symlink",
Glob: "*.html",
Expected: []string{
"1.html",
"3.html",
"first/4.html",
"second/4.html",
},
})
}
TEST:
for i, d := range matchingNamesData {
resolved, err := filepath.EvalSymlinks(d.Directory)
if err != nil {
t.Fatalf("test %d: cannot resolve %q: %+v", i, d.Directory, err)
}
fsys := os.DirFS(resolved)
files, err := matchingNames(fsys, d.Glob)
if d.ExpectedErr != "" {
if err == nil || err.Error() != d.ExpectedErr {
t.Fatalf("Expected error %q, got %+v", d.ExpectedErr, err)
}
continue TEST
}
if err != nil {
t.Fatalf("test %d (%s): err %+v", i, d.Directory, err)
}
if len(files) != len(d.Expected) {
for _, f := range files {
fmt.Println(f)
}
t.Fatalf("test %d (%s): different lengths: %d vs %d", i, d.Directory, len(files), len(d.Expected))
}
for j := range files {
if files[j] != d.Expected[j] {
t.Fatalf("test %d (%s): %d : %q != %q", i, d.Directory, j, files[j], d.Expected[j])
}
}
}
}