41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package notify
|
|
|
|
import "context"
|
|
|
|
// NoopSender is a deterministic no-op notifier.
|
|
type NoopSender struct{}
|
|
|
|
// Send returns a placeholder successful result.
|
|
func (n *NoopSender) Send(ctx context.Context, _ SendRequest) (SendResult, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return SendResult{}, err
|
|
}
|
|
return SendResult{ProviderMessageID: "noop", Metadata: map[string]any{"placeholder": true}}, nil
|
|
}
|
|
|
|
// FakeSender captures send requests and returns deterministic responses.
|
|
type FakeSender struct {
|
|
Requests []SendRequest
|
|
Err error
|
|
Result SendResult
|
|
}
|
|
|
|
// Send records request and returns configured response.
|
|
func (f *FakeSender) Send(ctx context.Context, req SendRequest) (SendResult, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return SendResult{}, err
|
|
}
|
|
f.Requests = append(f.Requests, req)
|
|
if f.Err != nil {
|
|
return SendResult{}, f.Err
|
|
}
|
|
res := f.Result
|
|
if res.ProviderMessageID == "" {
|
|
res.ProviderMessageID = "fake"
|
|
}
|
|
if res.Metadata == nil {
|
|
res.Metadata = map[string]any{"fake": true}
|
|
}
|
|
return res, nil
|
|
}
|