-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealthy_test.go
91 lines (85 loc) · 2.05 KB
/
healthy_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
package healthy
import (
"testing"
)
func TestNew(t *testing.T) {
type args struct {
serviceName string
version string
checkers []Checker
}
tests := []struct {
name string
args args
wantName string
wantVersion string
wantErr bool
}{
{
name: "when the name is missing we should get an error",
args: args{
serviceName: "",
version: "1.2.3",
checkers: []Checker{NewChecker("hello", NewMockChecker(nil))},
},
wantErr: true,
wantVersion: "",
},
{
name: "when the version is missing we should get an error",
args: args{
serviceName: "hello",
version: "",
checkers: []Checker{NewChecker("hello", NewMockChecker(nil))},
},
wantErr: true,
wantVersion: "",
wantName: "",
},
{
name: "when the checkers is passed as nil, it should be populated",
args: args{
serviceName: "hello",
version: "1.2.3",
checkers: []Checker{NewChecker("hello", NewMockChecker(nil))},
},
wantErr: false,
wantName: "hello",
wantVersion: "1.2.3",
},
{
name: "when the checkers have duplicated names, it should error",
args: args{
serviceName: "hello",
version: "1.2.3",
checkers: []Checker{
NewChecker("hello", NewMockChecker(nil)),
NewChecker("hello", NewMockChecker(nil)),
},
},
wantErr: true,
wantName: "hello",
wantVersion: "1.2.3",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := New(tt.args.serviceName, tt.args.version, tt.args.checkers...)
if (err != nil) != tt.wantErr {
t.Errorf("wanted error to be %v but got %v", tt.wantErr, err)
}
if got.Name() != tt.wantName {
t.Errorf("wanted name to be %s but got %s\n", tt.wantName, got.Name())
return
}
if got.Version() != tt.wantVersion {
t.Errorf("wanted version to be %s but got %s\n", tt.wantVersion, got.Version())
return
}
if got.Checkers() == nil {
t.Error("we never want checkers to be nil - always empty array")
return
}
})
}
}