diff --git a/alerting/provider/pagerduty/pagerduty.go b/alerting/provider/pagerduty/pagerduty.go index 09583e65..aa01994c 100644 --- a/alerting/provider/pagerduty/pagerduty.go +++ b/alerting/provider/pagerduty/pagerduty.go @@ -9,6 +9,10 @@ import ( "github.com/TwinProduction/gatus/core" ) +const ( + restAPIURL = "https://events.pagerduty.com/v2/enqueue" +) + // AlertProvider is the configuration necessary for sending an alert using PagerDuty type AlertProvider struct { IntegrationKey string `yaml:"integration-key"` @@ -37,7 +41,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler resolveKey = "" } return &custom.AlertProvider{ - URL: "https://events.pagerduty.com/v2/enqueue", + URL: restAPIURL, Method: http.MethodPost, Body: fmt.Sprintf(`{ "routing_key": "%s", diff --git a/client/client.go b/client/client.go index fc2fce02..79933d0f 100644 --- a/client/client.go +++ b/client/client.go @@ -16,7 +16,10 @@ import ( // GetHTTPClient returns the shared HTTP client func GetHTTPClient(config *Config) *http.Client { - return config.GetHTTPClient() + if config == nil { + return defaultConfig.getHTTPClient() + } + return config.getHTTPClient() } // CanCreateTCPConnection checks whether a connection can be established with a TCP service diff --git a/client/client_test.go b/client/client_test.go index 43f1d062..7f1046f9 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -6,12 +6,18 @@ import ( ) func TestGetHTTPClient(t *testing.T) { - GetHTTPClient(&Config{ + cfg := &Config{ Insecure: false, IgnoreRedirect: false, Timeout: 0, - httpClient: nil, - }) + } + cfg.ValidateAndSetDefaults() + if GetHTTPClient(cfg) == nil { + t.Error("expected client to not be nil") + } + if GetHTTPClient(nil) == nil { + t.Error("expected client to not be nil") + } } func TestPing(t *testing.T) { diff --git a/client/config.go b/client/config.go index e8c45006..176b41ec 100644 --- a/client/config.go +++ b/client/config.go @@ -47,7 +47,7 @@ func (c *Config) ValidateAndSetDefaults() { } // GetHTTPClient return a HTTP client matching the Config's parameters. -func (c *Config) GetHTTPClient() *http.Client { +func (c *Config) getHTTPClient() *http.Client { if c.httpClient == nil { c.httpClient = &http.Client{ Timeout: c.Timeout, diff --git a/client/config_test.go b/client/config_test.go index 7fe6576f..bf493d34 100644 --- a/client/config_test.go +++ b/client/config_test.go @@ -6,10 +6,10 @@ import ( "time" ) -func TestConfig_GetHTTPClient(t *testing.T) { +func TestConfig_getHTTPClient(t *testing.T) { insecureConfig := &Config{Insecure: true} insecureConfig.ValidateAndSetDefaults() - insecureClient := insecureConfig.GetHTTPClient() + insecureClient := insecureConfig.getHTTPClient() if !(insecureClient.Transport).(*http.Transport).TLSClientConfig.InsecureSkipVerify { t.Error("expected Config.Insecure set to true to cause the HTTP client to skip certificate verification") } @@ -23,7 +23,7 @@ func TestConfig_GetHTTPClient(t *testing.T) { secureConfig := &Config{IgnoreRedirect: true, Timeout: 5 * time.Second} secureConfig.ValidateAndSetDefaults() - secureClient := secureConfig.GetHTTPClient() + secureClient := secureConfig.getHTTPClient() if (secureClient.Transport).(*http.Transport).TLSClientConfig.InsecureSkipVerify { t.Error("expected Config.Insecure set to false to cause the HTTP client to not skip certificate verification") }