mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 06:06:38 +01:00
feat(notifications): add title field to template data (#1125)
This commit is contained in:
parent
1d59fb83dd
commit
aa02d8d31b
9 changed files with 94 additions and 35 deletions
|
|
@ -28,6 +28,27 @@ var _ = Describe("notifications", func() {
|
|||
|
||||
Expect(notif.GetNames()).To(BeEmpty())
|
||||
})
|
||||
When("title is overriden in flag", func() {
|
||||
It("should use the specified hostname in the title", func() {
|
||||
command := cmd.NewRootCommand()
|
||||
flags.RegisterNotificationFlags(command)
|
||||
|
||||
err := command.ParseFlags([]string{
|
||||
"--notifications-hostname",
|
||||
"test.host",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
hostname := notifications.GetHostname(command)
|
||||
title := notifications.GetTitle(hostname)
|
||||
Expect(title).To(Equal("Watchtower updates on test.host"))
|
||||
})
|
||||
})
|
||||
When("no hostname can be resolved", func() {
|
||||
It("should use the default simple title", func() {
|
||||
title := notifications.GetTitle("")
|
||||
Expect(title).To(Equal("Watchtower updates"))
|
||||
})
|
||||
})
|
||||
})
|
||||
Describe("the slack notifier", func() {
|
||||
// builderFn := notifications.NewSlackNotifier
|
||||
|
|
@ -39,7 +60,8 @@ var _ = Describe("notifications", func() {
|
|||
channel := "123456789"
|
||||
token := "abvsihdbau"
|
||||
color := notifications.ColorInt
|
||||
title := url.QueryEscape(notifications.GetTitle(command))
|
||||
hostname := notifications.GetHostname(command)
|
||||
title := url.QueryEscape(notifications.GetTitle(hostname))
|
||||
expected := fmt.Sprintf("discord://%s@%s?color=0x%x&colordebug=0x0&colorerror=0x0&colorinfo=0x0&colorwarn=0x0&title=%s&username=watchtower", token, channel, color, title)
|
||||
buildArgs := func(url string) []string {
|
||||
return []string{
|
||||
|
|
@ -67,7 +89,8 @@ var _ = Describe("notifications", func() {
|
|||
tokenB := "BBBBBBBBB"
|
||||
tokenC := "123456789123456789123456"
|
||||
color := url.QueryEscape(notifications.ColorHex)
|
||||
title := url.QueryEscape(notifications.GetTitle(command))
|
||||
hostname := notifications.GetHostname(command)
|
||||
title := url.QueryEscape(notifications.GetTitle(hostname))
|
||||
iconURL := "https://containrrr.dev/watchtower-sq180.png"
|
||||
iconEmoji := "whale"
|
||||
|
||||
|
|
@ -122,7 +145,8 @@ var _ = Describe("notifications", func() {
|
|||
|
||||
token := "aaa"
|
||||
host := "shoutrrr.local"
|
||||
title := url.QueryEscape(notifications.GetTitle(command))
|
||||
hostname := notifications.GetHostname(command)
|
||||
title := url.QueryEscape(notifications.GetTitle(hostname))
|
||||
|
||||
expectedOutput := fmt.Sprintf("gotify://%s/%s?title=%s", host, token, title)
|
||||
|
||||
|
|
@ -150,7 +174,8 @@ var _ = Describe("notifications", func() {
|
|||
tokenB := "33333333012222222222333333333344"
|
||||
tokenC := "44444444-4444-4444-8444-cccccccccccc"
|
||||
color := url.QueryEscape(notifications.ColorHex)
|
||||
title := url.QueryEscape(notifications.GetTitle(command))
|
||||
hostname := notifications.GetHostname(command)
|
||||
title := url.QueryEscape(notifications.GetTitle(hostname))
|
||||
|
||||
hookURL := fmt.Sprintf("https://outlook.office.com/webhook/%s/IncomingWebhook/%s/%s", tokenA, tokenB, tokenC)
|
||||
expectedOutput := fmt.Sprintf("teams://%s/%s/%s?color=%s&title=%s", tokenA, tokenB, tokenC, color, title)
|
||||
|
|
@ -241,7 +266,9 @@ func testURL(args []string, expectedURL string) {
|
|||
err := command.ParseFlags(args)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
urls, _ := notifications.AppendLegacyUrls([]string{}, command)
|
||||
hostname := notifications.GetHostname(command)
|
||||
title := notifications.GetTitle(hostname)
|
||||
urls, _ := notifications.AppendLegacyUrls([]string{}, command, title)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue