Define adapter interfaces and fake implementations
This commit is contained in:
40
internal/adapters/notify/fake.go
Normal file
40
internal/adapters/notify/fake.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user