mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 06:06:38 +01:00
Add string functions for lowercase, uppercase and capitalize to shoutrrr templates (#593)
* Added string functions for lowercase, uppercase and capitalize to shoutrrr templates * Update pkg/notifications/shoutrrr.go Co-authored-by: nils måsén <nils@piksel.se> * Update pkg/notifications/shoutrrr.go Co-authored-by: nils måsén <nils@piksel.se> * Update pkg/notifications/shoutrrr.go Co-authored-by: nils måsén <nils@piksel.se> * Update pkg/notifications/shoutrrr_test.go Co-authored-by: nils måsén <nils@piksel.se> * escape quotation marks in test Co-authored-by: nils måsén <nils@piksel.se>
This commit is contained in:
parent
d0f3ea3683
commit
f76c48a95e
2 changed files with 33 additions and 2 deletions
|
|
@ -51,6 +51,30 @@ func TestShoutrrrTemplate(t *testing.T) {
|
|||
require.Equal(t, "info: foo bar\n", s)
|
||||
}
|
||||
|
||||
func TestShoutrrrStringFunctions(t *testing.T) {
|
||||
cmd := new(cobra.Command)
|
||||
flags.RegisterNotificationFlags(cmd)
|
||||
err := cmd.ParseFlags([]string{"--notification-template={{range .}}{{.Level | printf \"%v\" | ToUpper }}: {{.Message | ToLower }} {{.Message | Title }}{{println}}{{end}}"})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
shoutrrr := &shoutrrrTypeNotifier{
|
||||
template: getShoutrrrTemplate(cmd),
|
||||
}
|
||||
|
||||
entries := []*log.Entry{
|
||||
{
|
||||
Level: log.InfoLevel,
|
||||
Message: "foo Bar",
|
||||
},
|
||||
}
|
||||
|
||||
s := shoutrrr.buildMessage(entries)
|
||||
|
||||
require.Equal(t, "INFO: foo bar Foo Bar\n", s)
|
||||
}
|
||||
|
||||
|
||||
func TestShoutrrrInvalidTemplateUsesTemplate(t *testing.T) {
|
||||
cmd := new(cobra.Command)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue