Skip to content

Commit

Permalink
fix slack URL and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Aug 16, 2021
1 parent 140186c commit ff30b37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/notifications/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func AppendLegacyUrls(urls []string, cmd *cobra.Command) []string {

shoutrrrURL, err := legacyNotifier.GetURL(cmd)
if err != nil {
log.Fatal("failed to create notification config:", err)
log.Fatal("failed to create notification config: ", err)
}
urls = append(urls, shoutrrrURL)

Expand Down
9 changes: 5 additions & 4 deletions pkg/notifications/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ var _ = Describe("notifications", func() {
flags.RegisterNotificationFlags(command)

username := "containrrrbot"
tokenA := "aaa"
tokenB := "bbb"
tokenC := "ccc"
tokenA := "AAAAAAAAA"
tokenB := "BBBBBBBBB"
tokenC := "123456789123456789123456"
color := url.QueryEscape(notifications.ColorHex)
title := url.QueryEscape(notifications.GetTitle(command))

hookURL := fmt.Sprintf("https://hooks.slack.com/services/%s/%s/%s", tokenA, tokenB, tokenC)
expectedOutput := fmt.Sprintf("slack://%s@%s/%s/%s?color=%s&title=%s", username, tokenA, tokenB, tokenC, color, title)
expectedOutput := fmt.Sprintf("slack://hook:%s-%s-%s@webhook?botname=%s&color=%s&title=%s", tokenA, tokenB, tokenC, username, color, title)

args := []string{
"--notifications",
Expand Down Expand Up @@ -208,6 +208,7 @@ func buildExpectedURL(username string, password string, host string, port int, f
}

func testURL(args []string, expectedURL string) {
defer GinkgoRecover()

command := cmd.NewRootCommand()
flags.RegisterNotificationFlags(command)
Expand Down
7 changes: 7 additions & 0 deletions pkg/notifications/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,16 @@ func (s *slackTypeNotifier) GetURL(c *cobra.Command) (string, error) {
conf := &shoutrrrSlack.Config{
BotName: s.Username,
Color: ColorHex,
Channel: "webhook",
Title: GetTitle(c),
}

if s.IconURL != "" {
conf.Icon = s.IconURL
} else if s.IconEmoji != "" {
conf.Icon = s.IconEmoji
}

if err := conf.Token.SetFromProp(webhookToken); err != nil {
return "", err
}
Expand Down

0 comments on commit ff30b37

Please sign in to comment.