-
Notifications
You must be signed in to change notification settings - Fork 0
/
healthcheck_test.go
59 lines (44 loc) · 2.03 KB
/
healthcheck_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
package healthcheck
import (
"testing"
tests "github.com/mundipagg/healthcheck-go/tests"
check "github.com/mundipagg/healthcheck-go/checks"
rabbit "github.com/mundipagg/healthcheck-go/checks/rabbit"
"github.com/stretchr/testify/assert"
)
func Test_Execute_WhenNoCheckConfigured_ShouldReturnHealthy(t *testing.T) {
healthCheck := New()
healthCheckResult := healthCheck.Execute()
assert.NotNil(t, healthCheckResult)
assert.Equal(t, healthCheckResult.Status, check.Healthy)
assert.Equal(t, len(healthCheckResult.Results), 0)
}
func Test_Execute_WhenRabbitWithInvalidConfiguration_ShouldReturnUnhealthy(t *testing.T) {
healthCheck := New()
config := &rabbit.Config{}
healthCheck.AddService(config)
healthCheckResult := healthCheck.Execute()
assert.NotNil(t, healthCheckResult)
assert.Equal(t, healthCheckResult.Status, check.Unhealthy)
assert.Equal(t, len(healthCheckResult.Results), 1)
assert.Contains(t, healthCheckResult.Results["rabbit"].Description, "ERROR:")
}
func Test_Execute_WhenDependenciesIsRunningWithValidConfiguration_ShouldReturnHealthy(t *testing.T) {
healthCheck := New()
configRabbit := tests.NewStubRabbitConfig()
configMongo := tests.NewStubMongoConfig()
configSqlServer := tests.NewStubSqlServerConfig()
healthCheck.AddService(configRabbit)
healthCheck.AddService(configMongo)
healthCheck.AddService(configSqlServer)
healthCheckResult := healthCheck.Execute()
assert.NotNil(t, healthCheckResult)
assert.Equal(t, healthCheckResult.Status, check.Healthy)
assert.Equal(t, len(healthCheckResult.Results), 3)
assert.Contains(t, healthCheckResult.Results["rabbit"].Status, check.Healthy)
assert.Contains(t, healthCheckResult.Results["rabbit"].Description, "rabbit is healthy")
assert.Contains(t, healthCheckResult.Results["mongo"].Status, check.Healthy)
assert.Contains(t, healthCheckResult.Results["mongo"].Description, "mongo is healthy")
assert.Contains(t, healthCheckResult.Results["sqlServer"].Status, check.Healthy)
assert.Contains(t, healthCheckResult.Results["sqlServer"].Description, "sqlServer is healthy")
}