.github
alerting
client
config
core
alert.go
condition.go
condition_test.go
service.go
service_test.go
types.go
docs
example
jsonpath
metric
pattern
security
static
vendor
watchdog
.dockerignore
.gitattributes
.gitignore
Dockerfile
LICENSE.md
README.md
config.yaml
go.mod
go.sum
gzip.go
main.go
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package core
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestIntegrationEvaluateHealth(t *testing.T) {
|
|
condition := Condition("[STATUS] == 200")
|
|
service := Service{
|
|
Name: "TwiNNatioN",
|
|
Url: "https://twinnation.org/health",
|
|
Conditions: []*Condition{&condition},
|
|
}
|
|
result := service.EvaluateHealth()
|
|
if !result.ConditionResults[0].Success {
|
|
t.Errorf("Condition '%s' should have been a success", condition)
|
|
}
|
|
if !result.Connected {
|
|
t.Error("Because the connection has been established, result.Connected should've been true")
|
|
}
|
|
if !result.Success {
|
|
t.Error("Because all conditions passed, this should have been a success")
|
|
}
|
|
}
|
|
|
|
func TestIntegrationEvaluateHealthWithFailure(t *testing.T) {
|
|
condition := Condition("[STATUS] == 500")
|
|
service := Service{
|
|
Name: "TwiNNatioN",
|
|
Url: "https://twinnation.org/health",
|
|
Conditions: []*Condition{&condition},
|
|
}
|
|
result := service.EvaluateHealth()
|
|
if result.ConditionResults[0].Success {
|
|
t.Errorf("Condition '%s' should have been a failure", condition)
|
|
}
|
|
if !result.Connected {
|
|
t.Error("Because the connection has been established, result.Connected should've been true")
|
|
}
|
|
if result.Success {
|
|
t.Error("Because one of the conditions failed, success should have been false")
|
|
}
|
|
}
|