Improve testing coverage for twilio and pagerduty providers

This commit is contained in:
TwinProduction 2020-10-21 21:34:01 -04:00
parent aa671bc72d
commit dca517e077
2 changed files with 37 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package pagerduty
import ( import (
"github.com/TwinProduction/gatus/core" "github.com/TwinProduction/gatus/core"
"strings"
"testing" "testing"
) )
@ -16,10 +17,24 @@ func TestAlertProvider_IsValid(t *testing.T) {
} }
} }
func TestAlertProvider_ToCustomAlertProvider(t *testing.T) { func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
provider := AlertProvider{IntegrationKey: "00000000000000000000000000000000"} provider := AlertProvider{IntegrationKey: "00000000000000000000000000000000"}
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, true) customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, true)
if customAlertProvider == nil { if customAlertProvider == nil {
t.Error("customAlertProvider shouldn't have been nil") t.Error("customAlertProvider shouldn't have been nil")
} }
if !strings.Contains(customAlertProvider.Body, "RESOLVED") {
t.Error("customAlertProvider.Body should've contained the substring RESOLVED")
}
}
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
provider := AlertProvider{IntegrationKey: "00000000000000000000000000000000"}
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, false)
if customAlertProvider == nil {
t.Error("customAlertProvider shouldn't have been nil")
}
if !strings.Contains(customAlertProvider.Body, "TRIGGERED") {
t.Error("customAlertProvider.Body should've contained the substring TRIGGERED")
}
} }

View File

@ -2,6 +2,7 @@ package twilio
import ( import (
"github.com/TwinProduction/gatus/core" "github.com/TwinProduction/gatus/core"
"strings"
"testing" "testing"
) )
@ -21,7 +22,7 @@ func TestTwilioAlertProvider_IsValid(t *testing.T) {
} }
} }
func TestAlertProvider_ToCustomAlertProvider(t *testing.T) { func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
provider := AlertProvider{ provider := AlertProvider{
SID: "1", SID: "1",
Token: "1", Token: "1",
@ -32,4 +33,23 @@ func TestAlertProvider_ToCustomAlertProvider(t *testing.T) {
if customAlertProvider == nil { if customAlertProvider == nil {
t.Error("customAlertProvider shouldn't have been nil") t.Error("customAlertProvider shouldn't have been nil")
} }
if !strings.Contains(customAlertProvider.Body, "RESOLVED") {
t.Error("customAlertProvider.Body should've contained the substring RESOLVED")
}
}
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
provider := AlertProvider{
SID: "1",
Token: "1",
From: "1",
To: "1",
}
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, false)
if customAlertProvider == nil {
t.Error("customAlertProvider shouldn't have been nil")
}
if !strings.Contains(customAlertProvider.Body, "TRIGGERED") {
t.Error("customAlertProvider.Body should've contained the substring TRIGGERED")
}
} }