-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
161 lines (155 loc) · 3.21 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import (
"reflect"
"testing"
"github.com/olebedev/config"
)
func Test_getConfig(t *testing.T) {
tests := []struct {
name string
wantCfg *config.Config
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
gotCfg, err := getConfig()
if (err != nil) != tt.wantErr {
t.Errorf("%q. getConfig() error = %v, wantErr %v", tt.name, err, tt.wantErr)
continue
}
if !reflect.DeepEqual(gotCfg, tt.wantCfg) {
t.Errorf("%q. getConfig() = %v, want %v", tt.name, gotCfg, tt.wantCfg)
}
}
}
func Test_prettyPrintFlagMap(t *testing.T) {
type args struct {
m map[string]interface{}
prefix []string
}
tests := []struct {
name string
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
prettyPrintFlagMap(tt.args.m, tt.args.prefix...)
}
}
func Test_combineConfigs(t *testing.T) {
type args struct {
cfgs []*config.Config
}
tests := []struct {
name string
args args
wantR *config.Config
}{
{
name: "Combine non-overlapping configs",
args: args{cfgs: []*config.Config{
{
Root: map[string]interface{}{
"log": map[string]interface{}{
"level": "debug",
},
},
},
{
Root: map[string]interface{}{
"remote": map[string]interface{}{
"addr": "google.com:443",
},
"log": map[string]interface{}{
"contents": true,
},
},
},
}},
wantR: &config.Config{
Root: map[string]interface{}{
"remote": map[string]interface{}{
"addr": "google.com:443",
},
"log": map[string]interface{}{
"level": "debug",
"contents": true,
},
},
},
},
{
name: "Combine overlapping configs",
args: args{cfgs: []*config.Config{
{
Root: map[string]interface{}{
"log": map[string]interface{}{
"level": "debug",
},
},
},
{
Root: map[string]interface{}{
"log": map[string]interface{}{
"level": "error",
},
},
},
}},
wantR: &config.Config{
Root: map[string]interface{}{
"log": map[string]interface{}{
"level": "error",
},
},
},
},
}
for _, tt := range tests {
if gotR := combineConfigs(tt.args.cfgs...); !reflect.DeepEqual(gotR, tt.wantR) {
t.Errorf("%q. combineConfigs() = %v, want %v", tt.name, gotR, tt.wantR)
} else {
t.Logf("%q. combineConfigs() = %v, want %v", tt.name, gotR, tt.wantR)
}
}
}
func Test_isCfgFile(t *testing.T) {
type args struct {
path string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Valid header",
args: args{path: "contrib/testdata/config/isCfgFile_true.yml"},
want: true,
},
{
name: "No header",
args: args{path: "contrib/testdata/config/isCfgFile_false.yml"},
want: false,
},
{
name: "Invalid header",
args: args{path: "contrib/testdata/config/isCfgFile_invalid.yml"},
want: false,
},
{
name: "Missing file",
args: args{path: "contrib/testdata/config/isCfgFile.yml"},
want: false,
},
}
for _, tt := range tests {
if got := isCfgFile(tt.args.path); got != tt.want {
t.Errorf("%q. isCfgFile() = %v, want %v", tt.name, got, tt.want)
} else {
t.Logf("%q. isCfgFile() = %v, want %v", tt.name, got, tt.want)
}
}
}