mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
Team's webhook API does not always use the status code to communicate errors. There are cases where it returns 200 and an error message in the body. For example, 429 - Too Many Requests or when the message is too large. Instead, what we should be looking for is a response body = "1". https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL#send-messages-using-curl-and-powershell
41 lines
836 B
Go
41 lines
836 B
Go
package notifications
|
|
|
|
import "fmt"
|
|
|
|
type FakeMailer struct {
|
|
Sent []*Message
|
|
}
|
|
|
|
func NewFakeMailer() *FakeMailer {
|
|
return &FakeMailer{
|
|
Sent: make([]*Message, 0),
|
|
}
|
|
}
|
|
|
|
func (fm *FakeMailer) Send(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(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
|
|
}
|