mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
e0402115ea
* Notifications: Optional trace propagation through SMTP Signed-off-by: Dave Henderson <dave.henderson@grafana.com> * fix failing test Signed-off-by: Dave Henderson <dave.henderson@grafana.com> * Add documentation Signed-off-by: Dave Henderson <dave.henderson@grafana.com> --------- Signed-off-by: Dave Henderson <dave.henderson@grafana.com>
44 lines
894 B
Go
44 lines
894 B
Go
package notifications
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
type FakeMailer struct {
|
|
Sent []*Message
|
|
}
|
|
|
|
func NewFakeMailer() *FakeMailer {
|
|
return &FakeMailer{
|
|
Sent: make([]*Message, 0),
|
|
}
|
|
}
|
|
|
|
func (fm *FakeMailer) Send(ctx context.Context, messages ...*Message) (int, error) {
|
|
sentEmailsCount := 0
|
|
for _, msg := range messages {
|
|
fm.Sent = append(fm.Sent, msg)
|
|
sentEmailsCount++
|
|
}
|
|
return sentEmailsCount, nil
|
|
}
|
|
|
|
type FakeDisconnectedMailer struct{}
|
|
|
|
func NewFakeDisconnectedMailer() *FakeDisconnectedMailer {
|
|
return &FakeDisconnectedMailer{}
|
|
}
|
|
|
|
func (fdm *FakeDisconnectedMailer) Send(ctx context.Context, messages ...*Message) (int, error) {
|
|
return 0, fmt.Errorf("connect: connection refused")
|
|
}
|
|
|
|
// NetClient is used to export original in test.
|
|
var NetClient = &netClient
|
|
|
|
// SetWebhookClient is used to mock in test.
|
|
func SetWebhookClient(client WebhookClient) {
|
|
netClient = client
|
|
}
|