Improve test coverage
This commit is contained in:
parent
20515b5dd4
commit
89ffc5a788
@ -5,6 +5,62 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestService_ValidateAndSetDefaults(t *testing.T) {
|
||||||
|
condition := Condition("[STATUS] == 200")
|
||||||
|
service := Service{
|
||||||
|
Name: "TwiNNatioN",
|
||||||
|
Url: "https://twinnation.org/health",
|
||||||
|
Conditions: []*Condition{&condition},
|
||||||
|
Alerts: []*Alert{{Type: PagerDutyAlert}},
|
||||||
|
}
|
||||||
|
service.ValidateAndSetDefaults()
|
||||||
|
if service.Method != "GET" {
|
||||||
|
t.Error("Service method should've defaulted to GET")
|
||||||
|
}
|
||||||
|
if service.Interval != time.Minute {
|
||||||
|
t.Error("Service interval should've defaulted to 1 minute")
|
||||||
|
}
|
||||||
|
if service.Headers == nil {
|
||||||
|
t.Error("Service headers should've defaulted to an empty map")
|
||||||
|
}
|
||||||
|
if len(service.Alerts) != 1 {
|
||||||
|
t.Error("Service should've had 1 alert")
|
||||||
|
}
|
||||||
|
if service.Alerts[0].Enabled {
|
||||||
|
t.Error("Service alert should've defaulted to disabled")
|
||||||
|
}
|
||||||
|
if service.Alerts[0].SuccessThreshold != 2 {
|
||||||
|
t.Error("Service alert should've defaulted to a success threshold of 2")
|
||||||
|
}
|
||||||
|
if service.Alerts[0].FailureThreshold != 3 {
|
||||||
|
t.Error("Service alert should've defaulted to a failure threshold of 3")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestService_GetAlertsTriggered(t *testing.T) {
|
||||||
|
condition := Condition("[STATUS] == 200")
|
||||||
|
service := Service{
|
||||||
|
Name: "TwiNNatioN",
|
||||||
|
Url: "https://twinnation.org/health",
|
||||||
|
Conditions: []*Condition{&condition},
|
||||||
|
Alerts: []*Alert{{Type: PagerDutyAlert, Enabled: true}},
|
||||||
|
}
|
||||||
|
service.ValidateAndSetDefaults()
|
||||||
|
if service.NumberOfFailuresInARow != 0 {
|
||||||
|
t.Error("Service.NumberOfFailuresInARow should start with 0")
|
||||||
|
}
|
||||||
|
if service.NumberOfSuccessesInARow != 0 {
|
||||||
|
t.Error("Service.NumberOfSuccessesInARow should start with 0")
|
||||||
|
}
|
||||||
|
if len(service.GetAlertsTriggered()) > 0 {
|
||||||
|
t.Error("No alerts should've been triggered, because service.NumberOfFailuresInARow is 0, which is below the failure threshold")
|
||||||
|
}
|
||||||
|
service.NumberOfFailuresInARow = service.Alerts[0].FailureThreshold
|
||||||
|
if len(service.GetAlertsTriggered()) != 1 {
|
||||||
|
t.Error("Alert should've been triggered")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIntegrationEvaluateHealth(t *testing.T) {
|
func TestIntegrationEvaluateHealth(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 200")
|
condition := Condition("[STATUS] == 200")
|
||||||
service := Service{
|
service := Service{
|
||||||
@ -42,35 +98,3 @@ func TestIntegrationEvaluateHealthWithFailure(t *testing.T) {
|
|||||||
t.Error("Because one of the conditions failed, success should have been false")
|
t.Error("Because one of the conditions failed, success should have been false")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestService_ValidateAndSetDefaults(t *testing.T) {
|
|
||||||
condition := Condition("[STATUS] == 200")
|
|
||||||
service := Service{
|
|
||||||
Name: "TwiNNatioN",
|
|
||||||
Url: "https://twinnation.org/health",
|
|
||||||
Conditions: []*Condition{&condition},
|
|
||||||
Alerts: []*Alert{{Type: PagerDutyAlert}},
|
|
||||||
}
|
|
||||||
service.ValidateAndSetDefaults()
|
|
||||||
if service.Method != "GET" {
|
|
||||||
t.Error("Service method should've defaulted to GET")
|
|
||||||
}
|
|
||||||
if service.Interval != time.Minute {
|
|
||||||
t.Error("Service interval should've defaulted to 1 minute")
|
|
||||||
}
|
|
||||||
if service.Headers == nil {
|
|
||||||
t.Error("Service headers should've defaulted to an empty map")
|
|
||||||
}
|
|
||||||
if len(service.Alerts) != 1 {
|
|
||||||
t.Error("Service should've had 1 alert")
|
|
||||||
}
|
|
||||||
if service.Alerts[0].Enabled {
|
|
||||||
t.Error("Service alert should've defaulted to disabled")
|
|
||||||
}
|
|
||||||
if service.Alerts[0].SuccessThreshold != 2 {
|
|
||||||
t.Error("Service alert should've defaulted to a success threshold of 2")
|
|
||||||
}
|
|
||||||
if service.Alerts[0].FailureThreshold != 3 {
|
|
||||||
t.Error("Service alert should've defaulted to a failure threshold of 3")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user