-
Notifications
You must be signed in to change notification settings - Fork 0
/
exists_test.go
82 lines (76 loc) · 1.9 KB
/
exists_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
package gfx_test
import (
"path/filepath"
"testing"
"github.com/goexl/gfx"
)
type (
in struct {
dirs [][]string
filename string
extensions []string
}
expected struct {
final string
exists bool
}
)
func TestExists(t *testing.T) {
tests := []struct {
in in
expected expected
}{{in: in{
dirs: [][]string{{
"testdata", "exists", "application",
}},
filename: "application",
extensions: []string{"yaml", "yml", "xml", "json", "toml"},
}, expected: expected{
final: filepath.Clean("testdata/exists/application/application.yaml"),
exists: true,
}}, {in: in{
dirs: [][]string{{
"testdata/exists/application",
}},
filename: "application",
extensions: []string{"toml", "yaml", "yml", "xml", "json"},
}, expected: expected{
final: filepath.Clean("testdata/exists/application/application.toml"),
exists: true,
}}, {in: in{
dirs: [][]string{{
"testdata", "exists", "application", "application",
}},
filename: "application",
extensions: []string{"toml", "yaml", "yml", "xml", "json"},
}, expected: expected{
exists: false,
}}, {in: in{
dirs: [][]string{{
"testdata", "exists", "application",
}, {
"testdata", "exists", "application", "application",
}},
filename: "application",
extensions: []string{"gfx", "gex"},
}, expected: expected{
exists: false,
}}}
for index, test := range tests {
exists := gfx.Exists().Filename(test.in.filename).Extension(test.in.extensions[0], test.in.extensions[1:]...)
for _, dir := range test.in.dirs {
exists.Directory(dir[0], dir[1:]...)
}
final, checked := exists.Build().Check()
if true == checked && true == test.expected.exists {
if final != test.expected.final {
t.Fatalf(
"第%d个测试不通过,期望:{final=%v, checked=%v},实际:{final=%v, exist=%v}",
index+1,
test.expected.final, test.expected.exists,
final, checked,
)
}
}
}
}