SimpleCloudNotifier/scnserver/push/testSink.go

44 lines
865 B
Go
Raw Permalink Normal View History

2022-11-23 20:21:49 +01:00
package push
import (
"blackforestbytes.com/simplecloudnotifier/models"
"context"
_ "embed"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
)
type SinkData struct {
Message models.Message
Client models.Client
CompatTitleOverride *string
2022-11-23 20:21:49 +01:00
}
type TestSink struct {
2022-11-30 17:58:04 +01:00
Data []SinkData
2022-11-23 20:21:49 +01:00
}
func NewTestSink() NotificationClient {
return &TestSink{}
}
2022-11-30 17:58:04 +01:00
func (d *TestSink) Last() SinkData {
return d.Data[len(d.Data)-1]
}
func (d *TestSink) SendNotification(ctx context.Context, client models.Client, msg models.Message, compatTitleOverride *string) (string, error) {
2022-11-23 20:21:49 +01:00
id, err := langext.NewHexUUID()
if err != nil {
return "", err
}
key := "TestSink[" + id + "]"
2022-11-30 17:58:04 +01:00
d.Data = append(d.Data, SinkData{
Message: msg,
Client: client,
CompatTitleOverride: compatTitleOverride,
2022-11-23 20:21:49 +01:00
})
return key, nil
}