Move alerting provider mocked tests at the watchdog level

This commit is contained in:
TwiN
2021-12-02 22:15:51 -05:00
parent f6336eac4e
commit 6954e9dde7
23 changed files with 279 additions and 176 deletions

View File

@ -2,11 +2,9 @@ package custom
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"github.com/TwiN/gatus/v3/alerting/alert"
@ -101,22 +99,13 @@ func (provider *AlertProvider) buildHTTPRequest(endpointName, alertDescription s
}
func (provider *AlertProvider) Send(endpoint *core.Endpoint, alert *alert.Alert, result *core.Result, resolved bool) error {
if os.Getenv("MOCK_ALERT_PROVIDER") == "true" {
if os.Getenv("MOCK_ALERT_PROVIDER_ERROR") == "true" {
return errors.New("error")
}
return nil
}
request := provider.buildHTTPRequest(endpoint.Name, alert.GetDescription(), resolved)
response, err := client.GetHTTPClient(provider.ClientConfig).Do(request)
if err != nil {
return err
}
if response.StatusCode > 399 {
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return fmt.Errorf("call to provider alert returned status code %d", response.StatusCode)
}
body, _ := ioutil.ReadAll(response.Body)
return fmt.Errorf("call to provider alert returned status code %d: %s", response.StatusCode, string(body))
}
return err