-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_test.go
68 lines (64 loc) · 1.97 KB
/
list_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
package gfx_test
import (
"path/filepath"
"reflect"
"testing"
"github.com/goexl/gfx"
)
func TestList(t *testing.T) {
tests := []struct {
in in
expected []string
}{{in: in{
dirs: [][]string{{
"testdata", "exists", "application",
}},
filename: "application",
extensions: []string{"yaml", "yml", "xml", "json", "toml"},
}, expected: []string{
filepath.Clean("testdata/exists/application/application.yaml"),
filepath.Clean("testdata/exists/application/application.yml"),
filepath.Clean("testdata/exists/application/application.xml"),
filepath.Clean("testdata/exists/application/application.json"),
filepath.Clean("testdata/exists/application/application.toml"),
}}, {in: in{
dirs: [][]string{{
"testdata/exists/application",
}},
filename: "application",
extensions: []string{"toml", "yaml", "xml", "json"},
}, expected: []string{
filepath.Clean("testdata/exists/application/application.toml"),
filepath.Clean("testdata/exists/application/application.yaml"),
filepath.Clean("testdata/exists/application/application.xml"),
filepath.Clean("testdata/exists/application/application.json"),
}}, {in: in{
dirs: [][]string{{
"testdata", "exists", "application", "application",
}},
filename: "application",
extensions: []string{"toml", "yaml", "yml", "xml", "json"},
}, expected: []string{
// 无
}}, {in: in{
dirs: [][]string{{
"testdata", "exists", "application",
}, {
"testdata", "exists", "application", "application",
}},
filename: "application",
extensions: []string{"gfx", "gex"},
}, expected: []string{
// 无
}}}
for index, test := range tests {
list := gfx.List().Filename(test.in.filename).Extension(test.in.extensions[0], test.in.extensions[1:]...)
for _, dir := range test.in.dirs {
list.Directory(dir[0], dir[1:]...)
}
files := list.Build().All()
if !reflect.DeepEqual(files, test.expected) {
t.Fatalf("第%d个测试出错,期望:%v,实际:%v", index+1, test.expected, files)
}
}
}