Improve test coverage

This commit is contained in:
TwinProduction 2020-12-18 18:06:57 -05:00
parent 4be2273662
commit 4d186c6e71

View File

@ -96,9 +96,6 @@ func TestService_GetAlertsTriggered(t *testing.T) {
URL: "https://twinnation.org/health",
Conditions: []*Condition{&condition},
Alerts: []*Alert{{Type: PagerDutyAlert, Enabled: true}},
Headers: map[string]string{
"Host": "twinnation.org",
},
}
service.ValidateAndSetDefaults()
if service.NumberOfFailuresInARow != 0 {
@ -116,6 +113,37 @@ func TestService_GetAlertsTriggered(t *testing.T) {
}
}
func TestService_buildHTTPRequest(t *testing.T) {
condition := Condition("[STATUS] == 200")
service := Service{
Name: "TwiNNatioN",
URL: "https://twinnation.org/health",
Conditions: []*Condition{&condition},
}
service.ValidateAndSetDefaults()
request := service.buildHTTPRequest()
if request.Host != "twinnation.org" {
t.Error("request's Host should've been twinnation.org, but was", request.Host)
}
}
func TestService_buildHTTPRequestWithHostHeader(t *testing.T) {
condition := Condition("[STATUS] == 200")
service := Service{
Name: "TwiNNatioN",
URL: "https://twinnation.org/health",
Conditions: []*Condition{&condition},
Headers: map[string]string{
"Host": "example.com",
},
}
service.ValidateAndSetDefaults()
request := service.buildHTTPRequest()
if request.Host != "example.com" {
t.Error("request's Host should've been example.org, but was", request.Host)
}
}
func TestIntegrationEvaluateHealth(t *testing.T) {
condition := Condition("[STATUS] == 200")
service := Service{