-
Notifications
You must be signed in to change notification settings - Fork 11
/
config_test.go
67 lines (63 loc) · 1.28 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
package main
import (
"path/filepath"
"reflect"
"testing"
)
func TestLoadOptionsFromConfig(t *testing.T) {
tt := []struct {
test string
configPath string
expected *OpenerOptions
expectedErr string
}{
{
"unix",
filepath.Join("testdata", "config", "unix.yaml"),
&OpenerOptions{
Network: "unix",
Address: "~/.opener.sock",
},
"",
},
{
"tcp",
filepath.Join("testdata", "config", "tcp.yaml"),
&OpenerOptions{
Network: "tcp",
Address: "127.0.0.1:9000",
},
"",
},
{
"empty",
filepath.Join("testdata", "config", "empty.yaml"),
&OpenerOptions{},
"",
},
{
"no such file",
filepath.Join("testdata", "config", "no-such-file.yaml"),
&OpenerOptions{},
"stat testdata/config/no-such-file.yaml: no such file or directory",
},
}
for _, tc := range tt {
t.Run(tc.test, func(t *testing.T) {
o := &OpenerOptions{}
err := LoadOpenerOptionsFromConfig(tc.configPath, o)
if err == nil {
if tc.expectedErr != "" {
t.Errorf("expected err nil, but %q", err)
}
} else {
if tc.expectedErr != err.Error() {
t.Errorf("expected err %q, but %q", tc.expectedErr, err)
}
}
if !reflect.DeepEqual(tc.expected, o) {
t.Errorf("expected %#v, but %#v", tc.expected, o)
}
})
}
}