Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(notifier): don't panic on unconfigured notifier #869

Merged
merged 1 commit into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/notifications/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions pkg/notifications/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down