From e434178a5c0bcee5008c8a7c5abd987c13d3e668 Mon Sep 17 00:00:00 2001 From: TwiN Date: Wed, 7 Sep 2022 19:02:30 -0400 Subject: [PATCH] test(alerting): Make sure ClientConfig is set after IsValid() call in Telegram provider --- alerting/provider/telegram/telegram_test.go | 26 ++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/alerting/provider/telegram/telegram_test.go b/alerting/provider/telegram/telegram_test.go index a4680438..c9691f17 100644 --- a/alerting/provider/telegram/telegram_test.go +++ b/alerting/provider/telegram/telegram_test.go @@ -12,14 +12,24 @@ import ( ) func TestAlertProvider_IsValid(t *testing.T) { - invalidProvider := AlertProvider{Token: "", ID: ""} - if invalidProvider.IsValid() { - t.Error("provider shouldn't have been valid") - } - validProvider := AlertProvider{Token: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11", ID: "12345678"} - if !validProvider.IsValid() { - t.Error("provider should've been valid") - } + t.Run("invalid-provider", func(t *testing.T) { + invalidProvider := AlertProvider{Token: "", ID: ""} + if invalidProvider.IsValid() { + t.Error("provider shouldn't have been valid") + } + }) + t.Run("valid-provider", func(t *testing.T) { + validProvider := AlertProvider{Token: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11", ID: "12345678"} + if validProvider.ClientConfig != nil { + t.Error("provider client config should have been nil prior to IsValid() being executed") + } + if !validProvider.IsValid() { + t.Error("provider should've been valid") + } + if validProvider.ClientConfig == nil { + t.Error("provider client config should have been set after IsValid() was executed") + } + }) } func TestAlertProvider_Send(t *testing.T) {