Improve alerting providers test coverage

This commit is contained in:
TwinProduction
2020-10-21 22:35:37 -04:00
parent 89ffc5a788
commit 8c61044e7c
2 changed files with 21 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package slack
import (
"github.com/TwinProduction/gatus/core"
"strings"
"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{WebhookUrl: "http://example.com"}
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, true)
if customAlertProvider == 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{WebhookUrl: "http://example.com"}
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")
}
}