mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 06:06:38 +01:00
Make sure all shoutrrr notifications are sent (#564)
This commit is contained in:
parent
b8408269bb
commit
fdecd40189
9 changed files with 122 additions and 15 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package notifications
|
||||
|
||||
import (
|
||||
"github.com/containrrr/shoutrrr/pkg/types"
|
||||
"testing"
|
||||
"text/template"
|
||||
|
||||
|
|
@ -102,3 +103,69 @@ func TestShoutrrrInvalidTemplateUsesTemplate(t *testing.T) {
|
|||
|
||||
require.Equal(t, sd, s)
|
||||
}
|
||||
|
||||
type blockingRouter struct {
|
||||
unlock chan bool
|
||||
sent chan bool
|
||||
}
|
||||
|
||||
func (b blockingRouter) Send(message string, params *types.Params) []error {
|
||||
_ = <-b.unlock
|
||||
b.sent <- true
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestSlowNotificationNotSent(t *testing.T) {
|
||||
_, blockingRouter := sendNotificationsWithBlockingRouter()
|
||||
|
||||
notifSent := false
|
||||
select {
|
||||
case notifSent = <-blockingRouter.sent:
|
||||
default:
|
||||
}
|
||||
|
||||
require.Equal(t, false, notifSent)
|
||||
}
|
||||
|
||||
func TestSlowNotificationSent(t *testing.T) {
|
||||
shoutrrr, blockingRouter := sendNotificationsWithBlockingRouter()
|
||||
|
||||
blockingRouter.unlock <- true
|
||||
shoutrrr.Close()
|
||||
|
||||
notifSent := false
|
||||
select {
|
||||
case notifSent = <-blockingRouter.sent:
|
||||
default:
|
||||
}
|
||||
require.Equal(t, true, notifSent)
|
||||
}
|
||||
|
||||
func sendNotificationsWithBlockingRouter() (*shoutrrrTypeNotifier, *blockingRouter) {
|
||||
cmd := new(cobra.Command)
|
||||
|
||||
router := &blockingRouter{
|
||||
unlock: make(chan bool, 1),
|
||||
sent: make(chan bool, 1),
|
||||
}
|
||||
|
||||
shoutrrr := &shoutrrrTypeNotifier{
|
||||
template: getShoutrrrTemplate(cmd),
|
||||
messages: make(chan string, 1),
|
||||
done: make(chan bool),
|
||||
Router: router,
|
||||
}
|
||||
|
||||
entry := &log.Entry{
|
||||
Message: "foo bar",
|
||||
}
|
||||
|
||||
go sendNotifications(shoutrrr)
|
||||
|
||||
shoutrrr.StartNotification()
|
||||
shoutrrr.Fire(entry)
|
||||
|
||||
shoutrrr.SendNotification()
|
||||
|
||||
return shoutrrr, router
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue