forked from shuLhan/go-bindata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
102 lines (93 loc) · 1.88 KB
/
config_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package bindata
import (
"os"
"path/filepath"
"testing"
)
func TestValidateInput(t *testing.T) {
tests := []struct {
desc string
cfg *Config
expErr string
}{{
desc: `With empty list`,
cfg: &Config{},
expErr: ErrNoInput.Error(),
}, {
desc: `With empty path`,
cfg: &Config{
Input: []InputConfig{{
Path: "",
}},
},
expErr: `Failed to stat input path '': lstat : no such file or directory`,
}, {
desc: `With directory not exist`,
cfg: &Config{
Input: []InputConfig{{
Path: "./notexist",
}},
},
expErr: `Failed to stat input path './notexist': lstat ./notexist: no such file or directory`,
}, {
desc: `With file as input`,
cfg: &Config{
Input: []InputConfig{{
Path: "./README.md",
}},
},
}}
for _, test := range tests {
t.Log(test.desc)
err := test.cfg.validateInput()
if err != nil {
assert(t, test.expErr, err.Error(), true)
continue
}
}
}
func TestValidateOutput(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
tests := []struct {
desc string
cfg *Config
expErr string
expOutput string
}{{
desc: `With empty`,
cfg: &Config{
cwd: cwd,
},
expOutput: filepath.Join(cwd, DefOutputName),
}, {
desc: `With unwriteable directory`,
cfg: &Config{
Output: "/root/.ssh/template.go",
},
expErr: `Create output directory: mkdir /root/.ssh/: permission denied`,
}, {
desc: `With unwriteable file`,
cfg: &Config{
Output: "/template.go",
},
expErr: `open /template.go: permission denied`,
}, {
desc: `With output as directory`,
cfg: &Config{
Output: "/tmp/",
},
expOutput: filepath.Join("/tmp", DefOutputName),
}}
for _, test := range tests {
t.Log(test.desc)
err := test.cfg.validateOutput()
if err != nil {
assert(t, test.expErr, err.Error(), true)
continue
}
assert(t, test.expOutput, test.cfg.Output, true)
}
}