-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_test.go
66 lines (64 loc) · 1.24 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
package main
import "testing"
func TestConfig_validate(t *testing.T) {
type fields struct {
Port int
BaseAssetsPath string
SecureKeys []string
}
init := func(opts ...func(f *fields)) fields {
f := fields{
Port: 1234,
BaseAssetsPath: "/path/to/assets",
SecureKeys: []string{"secure key"},
}
for _, opt := range opts {
opt(&f)
}
return f
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "Success Case 1",
fields: init(),
wantErr: false,
},
{
name: "Bad Port",
fields: init(func(f *fields) {
f.Port = -1
}),
wantErr: true,
},
{
name: "Empty Assets Path",
fields: init(func(f *fields) {
f.BaseAssetsPath = ""
}),
wantErr: true,
},
{
name: "Empty Secure Key",
fields: init(func(f *fields) {
f.SecureKeys = []string{}
}),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Config{
Port: tt.fields.Port,
BaseAssetsPath: tt.fields.BaseAssetsPath,
SecureKeys: tt.fields.SecureKeys,
}
if got := c.validate(); tt.wantErr != (got != nil) {
t.Errorf("Config.validate() = %v, want error? %v", got, tt.wantErr)
}
})
}
}