add tests for webhook events (#2180)

* add tests for webhook events

* atomic.Uint32 is not in Go 1.18
This commit is contained in:
Matthew Donoughe
2022-10-09 22:55:54 -07:00
committed by GitHub
parent 155d671df0
commit 10055664bb
10 changed files with 596 additions and 12 deletions
+10 -1
View File
@@ -1,6 +1,7 @@
package webhooks
import (
"sync"
"time"
"github.com/owncast/owncast/core/data"
@@ -27,9 +28,17 @@ type WebhookChatMessage struct {
// SendEventToWebhooks will send a single webhook event to all webhook destinations.
func SendEventToWebhooks(payload WebhookEvent) {
sendEventToWebhooks(payload, nil)
}
func sendEventToWebhooks(payload WebhookEvent, wg *sync.WaitGroup) {
webhooks := data.GetWebhooksForEvent(payload.Type)
for _, webhook := range webhooks {
go addToQueue(webhook, payload)
// Use wg to track the number of notifications to be sent.
if wg != nil {
wg.Add(1)
}
addToQueue(webhook, payload, wg)
}
}