From 77de4c474273a6dce9939e10ae9051e81bc7531d Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Sat, 15 May 2021 21:54:23 -0400 Subject: [PATCH] Minor fixes --- alerting/provider/telegram/telegram_test.go | 3 +- alerting/provider/twilio/twilio_test.go | 6 ++-- watchdog/alerting_test.go | 36 +++++++++++++-------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/alerting/provider/telegram/telegram_test.go b/alerting/provider/telegram/telegram_test.go index c4e7631b..7a56df60 100644 --- a/alerting/provider/telegram/telegram_test.go +++ b/alerting/provider/telegram/telegram_test.go @@ -46,7 +46,8 @@ func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) { func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) { provider := AlertProvider{Token: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11", ID: "0123456789"} - customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{Description: "Healthcheck Successful"}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "UNSUCCESSFUL_CONDITION", Success: false}}}, false) + description := "Healthcheck Successful" + customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{Description: &description}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "UNSUCCESSFUL_CONDITION", Success: false}}}, false) if customAlertProvider == nil { t.Fatal("customAlertProvider shouldn't have been nil") } diff --git a/alerting/provider/twilio/twilio_test.go b/alerting/provider/twilio/twilio_test.go index 46dcfc49..4b89a393 100644 --- a/alerting/provider/twilio/twilio_test.go +++ b/alerting/provider/twilio/twilio_test.go @@ -31,7 +31,8 @@ func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) { From: "3", To: "4", } - customAlertProvider := provider.ToCustomAlertProvider(&core.Service{Name: "service-name"}, &core.Alert{Description: "alert-description"}, &core.Result{}, true) + description := "alert-description" + customAlertProvider := provider.ToCustomAlertProvider(&core.Service{Name: "service-name"}, &core.Alert{Description: &description}, &core.Result{}, true) if customAlertProvider == nil { t.Fatal("customAlertProvider shouldn't have been nil") } @@ -56,7 +57,8 @@ func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) { From: "2", To: "1", } - customAlertProvider := provider.ToCustomAlertProvider(&core.Service{Name: "service-name"}, &core.Alert{Description: "alert-description"}, &core.Result{}, false) + description := "alert-description" + customAlertProvider := provider.ToCustomAlertProvider(&core.Service{Name: "service-name"}, &core.Alert{Description: &description}, &core.Result{}, false) if customAlertProvider == nil { t.Fatal("customAlertProvider shouldn't have been nil") } diff --git a/watchdog/alerting_test.go b/watchdog/alerting_test.go index e1973af3..acf056b2 100644 --- a/watchdog/alerting_test.go +++ b/watchdog/alerting_test.go @@ -25,15 +25,16 @@ func TestHandleAlerting(t *testing.T) { }, } config.Set(cfg) + enabled := true service := &core.Service{ URL: "http://example.com", Alerts: []*core.Alert{ { Type: core.CustomAlert, - Enabled: true, + Enabled: &enabled, FailureThreshold: 2, SuccessThreshold: 3, - SendOnResolved: true, + SendOnResolved: &enabled, Triggered: false, }, }, @@ -78,15 +79,16 @@ func TestHandleAlertingWithBadAlertProvider(t *testing.T) { Alerting: &alerting.Config{}, } config.Set(cfg) + enabled := true service := &core.Service{ URL: "http://example.com", Alerts: []*core.Alert{ { Type: core.CustomAlert, - Enabled: true, + Enabled: &enabled, FailureThreshold: 1, SuccessThreshold: 1, - SendOnResolved: true, + SendOnResolved: &enabled, Triggered: false, }, }, @@ -113,15 +115,16 @@ func TestHandleAlertingWhenTriggeredAlertIsAlmostResolvedButServiceStartFailingA }, } config.Set(cfg) + enabled := true service := &core.Service{ URL: "http://example.com", Alerts: []*core.Alert{ { Type: core.CustomAlert, - Enabled: true, + Enabled: &enabled, FailureThreshold: 2, SuccessThreshold: 3, - SendOnResolved: true, + SendOnResolved: &enabled, Triggered: true, }, }, @@ -147,15 +150,17 @@ func TestHandleAlertingWhenTriggeredAlertIsResolvedButSendOnResolvedIsFalse(t *t }, } config.Set(cfg) + enabled := true + disabled := false service := &core.Service{ URL: "http://example.com", Alerts: []*core.Alert{ { Type: core.CustomAlert, - Enabled: true, + Enabled: &enabled, FailureThreshold: 1, SuccessThreshold: 1, - SendOnResolved: false, + SendOnResolved: &disabled, Triggered: true, }, }, @@ -179,15 +184,16 @@ func TestHandleAlertingWhenTriggeredAlertIsResolvedPagerDuty(t *testing.T) { }, } config.Set(cfg) + enabled := true service := &core.Service{ URL: "http://example.com", Alerts: []*core.Alert{ { Type: core.PagerDutyAlert, - Enabled: true, + Enabled: &enabled, FailureThreshold: 1, SuccessThreshold: 1, - SendOnResolved: true, + SendOnResolved: &enabled, Triggered: false, }, }, @@ -215,15 +221,16 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) { }, } config.Set(cfg) + enabled := true service := &core.Service{ URL: "http://example.com", Alerts: []*core.Alert{ { Type: core.CustomAlert, - Enabled: true, + Enabled: &enabled, FailureThreshold: 2, SuccessThreshold: 2, - SendOnResolved: true, + SendOnResolved: &enabled, Triggered: false, }, }, @@ -273,15 +280,16 @@ func TestHandleAlertingWithProviderThatOnlyReturnsErrorOnResolve(t *testing.T) { }, } config.Set(cfg) + enabled := true service := &core.Service{ URL: "http://example.com", Alerts: []*core.Alert{ { Type: core.CustomAlert, - Enabled: true, + Enabled: &enabled, FailureThreshold: 1, SuccessThreshold: 1, - SendOnResolved: true, + SendOnResolved: &enabled, Triggered: false, }, },