-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
92 lines (81 loc) · 2.52 KB
/
main_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
package gohealthwatch_test
import (
"net/http"
"testing"
gohealthwatch "github.com/pcpratheesh/go-healthwatch"
"github.com/pcpratheesh/go-healthwatch/config"
"github.com/pcpratheesh/go-healthwatch/constants"
"github.com/pcpratheesh/go-healthwatch/utils/errors"
"github.com/stretchr/testify/require"
)
func TestHealthWatch(t *testing.T) {
t.Run("", func(t *testing.T) {
checker := gohealthwatch.NewChecker(
gohealthwatch.WithIntegrations([]config.HealthCheckConfig{
{
Name: "public-entries",
URL: "https://api.publicapis.org/entries",
Type: constants.External,
StatusCode: http.StatusOK,
Interval: -1,
},
}),
gohealthwatch.WithServiceStatusWebHook(func(check config.HealthCheckConfig, statusCode constants.HealthCheckStatus, err errors.Error) {
if check.GetName() == "public-entries" {
require.Equal(t, constants.Success, statusCode)
}
}),
)
checker.Check()
})
}
func TestHealthWatchWithCustomhandler(t *testing.T) {
t.Run("", func(t *testing.T) {
checker := gohealthwatch.NewChecker(
gohealthwatch.WithIntegrations([]config.HealthCheckConfig{
{
Name: "public-entries",
URL: "no-url",
Type: constants.External,
StatusCode: http.StatusOK,
Interval: -1,
},
}),
gohealthwatch.WithServiceStatusWebHook(func(check config.HealthCheckConfig, statusCode constants.HealthCheckStatus, err errors.Error) {
if check.GetName() == "public-entries" {
require.Equal(t, constants.Success, statusCode)
}
}),
)
// add custom handler for public-entries
checker.AddCheck("public-entries", func(check config.HealthCheckConfig) errors.Error {
return nil
})
checker.Check()
})
}
func TestHealthWatchWithCustomhandlerFailure(t *testing.T) {
t.Run("", func(t *testing.T) {
checker := gohealthwatch.NewChecker(
gohealthwatch.WithIntegrations([]config.HealthCheckConfig{
{
Name: "public-entries",
URL: "no-url",
Type: constants.External,
StatusCode: http.StatusOK,
Interval: -1,
},
}),
gohealthwatch.WithServiceStatusWebHook(func(check config.HealthCheckConfig, statusCode constants.HealthCheckStatus, err errors.Error) {
if check.GetName() == "public-entries" {
require.Equal(t, constants.Failure, statusCode)
}
}),
)
// add custom handler for public-entries
checker.AddCheck("public-entries", func(check config.HealthCheckConfig) errors.Error {
return errors.New("trigger-failure", "")
})
checker.Check()
})
}