-
Notifications
You must be signed in to change notification settings - Fork 58
/
health_shared_test.go
55 lines (45 loc) · 1.01 KB
/
health_shared_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
package health
import (
"fmt"
"time"
"github.com/InVisionApp/go-health/v2/fakes"
"github.com/InVisionApp/go-logger"
)
func setupRunners(cfgs []*Config, logger log.Logger) (*Health, []*Config, error) {
h := New()
testCheckInterval := time.Duration(10) * time.Millisecond
if cfgs == nil {
checker1 := &fakes.FakeICheckable{}
checker2 := &fakes.FakeICheckable{}
cfgs = []*Config{
{
Name: "foo",
Checker: checker1,
Interval: testCheckInterval,
Fatal: false,
},
{
Name: "bar",
Checker: checker2,
Interval: testCheckInterval,
Fatal: false,
},
}
}
if err := h.AddChecks(cfgs); err != nil {
return nil, nil, err
}
if logger != nil {
h.Logger = logger
} else {
h.Logger = log.NewNoop()
}
if err := h.Start(); err != nil {
return nil, nil, err
}
// Correct number of runners/tickers were created
if len(h.runners) != len(cfgs) {
return nil, nil, fmt.Errorf("Start() did not create the expected number of runners")
}
return h, cfgs, nil
}