generated from axetroy/go-cli-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 8
/
config_test.go
75 lines (71 loc) · 1.35 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
package watchdog
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestConfig_Validate(t *testing.T) {
type fields struct {
Interval uint
Service []Service
}
tests := []struct {
name string
fields fields
err string
}{
{
name: "missing global interval config",
fields: fields{
Service: make([]Service, 0),
},
err: "Config.Interval is required!",
},
{
name: "missing service",
fields: fields{
Interval: 10,
},
err: "Config.Service is required!",
},
{
name: "service property",
fields: fields{
Interval: 10,
Service: []Service{
{
Name: "",
},
},
},
err: "Config.Service[0].Addr is required!\nConfig.Service[0].Interval must be greater than 0\nConfig.Service[0].Name is required!\nConfig.Service[0].Protocol is required!",
},
{
name: "none error",
fields: fields{
Interval: 10,
Service: []Service{
{
Name: "test",
Addr: "localhost:22",
Protocol: "ssh",
Interval: 10,
},
},
},
err: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Config{
Interval: tt.fields.Interval,
Service: tt.fields.Service,
}
if tt.err == "" {
assert.Nil(t, c.Validate(), tt.name)
} else {
assert.EqualError(t, c.Validate(), tt.err, tt.name)
}
})
}
}