From e1a5452bd023c41c017cfca2691ead1e0619f9b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nils=20m=C3=A5s=C3=A9n?= Date: Tue, 30 Mar 2021 13:45:02 +0200 Subject: [PATCH] fix(notifier): don't panic on unconfigured notifier --- pkg/notifications/notifier.go | 6 ++++++ pkg/notifications/notifier_test.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/pkg/notifications/notifier.go b/pkg/notifications/notifier.go index b9e322e7c..ec313a508 100644 --- a/pkg/notifications/notifier.go +++ b/pkg/notifications/notifier.go @@ -55,6 +55,12 @@ func (n *Notifier) String() string { sb.WriteString(", ") } } + + if sb.Len() < 2 { + // No notification services are configured, return early as the separator strip is not applicable + return "none" + } + names := sb.String() // remove the last separator diff --git a/pkg/notifications/notifier_test.go b/pkg/notifications/notifier_test.go index 5ef75a02e..ecd228f33 100644 --- a/pkg/notifications/notifier_test.go +++ b/pkg/notifications/notifier_test.go @@ -23,6 +23,22 @@ func TestActions(t *testing.T) { } var _ = Describe("notifications", func() { + Describe("the notifier", func() { + When("only empty notifier types are provided", func() { + + command := cmd.NewRootCommand() + flags.RegisterNotificationFlags(command) + + err := command.ParseFlags([]string{ + "--notifications", + "shoutrrr", + }) + Expect(err).NotTo(HaveOccurred()) + notif := notifications.NewNotifier(command) + + Expect(notif.String()).To(Equal("none")) + }) + }) Describe("the slack notifier", func() { builderFn := notifications.NewSlackNotifier