diff --git a/service/pagerduty/config.go b/service/pagerduty/config.go index 7b646972..177f77c9 100644 --- a/service/pagerduty/config.go +++ b/service/pagerduty/config.go @@ -1,6 +1,7 @@ package pagerduty import ( + "errors" "fmt" "net/mail" @@ -33,7 +34,7 @@ func NewConfig() *Config { // It returns an error if the configuration is invalid. func (c *Config) OK() error { if c.FromAddress == "" { - return fmt.Errorf("from address is required") + return errors.New("from address is required") } _, err := mail.ParseAddress(c.FromAddress) @@ -42,11 +43,11 @@ func (c *Config) OK() error { } if len(c.Receivers) == 0 { - return fmt.Errorf("at least one receiver is required") + return errors.New("at least one receiver is required") } if c.NotificationType == "" { - return fmt.Errorf("notification type is required") + return errors.New("notification type is required") } return nil diff --git a/service/pagerduty/config_test.go b/service/pagerduty/config_test.go index a30428cf..5df324e7 100644 --- a/service/pagerduty/config_test.go +++ b/service/pagerduty/config_test.go @@ -1,7 +1,7 @@ package pagerduty_test import ( - "fmt" + "errors" "testing" gopagerduty "github.com/PagerDuty/go-pagerduty" @@ -56,7 +56,7 @@ func TestConfig_OK(t *testing.T) { config: &pagerduty.Config{ Receivers: []string{"AB1234", "CD5678"}, }, - wantErr: fmt.Errorf("from address is required"), + wantErr: errors.New("from address is required"), }, { name: "invalid_from_address", @@ -64,14 +64,14 @@ func TestConfig_OK(t *testing.T) { FromAddress: "senderdomain.com", Receivers: []string{"AB1234", "CD5678"}, }, - wantErr: fmt.Errorf("from address is invalid: mail: missing '@' or angle-addr"), + wantErr: errors.New("from address is invalid: mail: missing '@' or angle-addr"), }, { name: "missing_receivers", config: &pagerduty.Config{ FromAddress: "sender@domain.com", }, - wantErr: fmt.Errorf("at least one receiver is required"), + wantErr: errors.New("at least one receiver is required"), }, { name: "missing_notification_type", @@ -79,7 +79,7 @@ func TestConfig_OK(t *testing.T) { FromAddress: "sender@domain.com", Receivers: []string{"AB1234", "CD5678"}, }, - wantErr: fmt.Errorf("notification type is required"), + wantErr: errors.New("notification type is required"), }, } diff --git a/service/pagerduty/pager_duty.go b/service/pagerduty/pager_duty.go index c3b984bd..7794e336 100644 --- a/service/pagerduty/pager_duty.go +++ b/service/pagerduty/pager_duty.go @@ -2,6 +2,7 @@ package pagerduty import ( "context" + "errors" "fmt" "github.com/PagerDuty/go-pagerduty" @@ -9,7 +10,7 @@ import ( ) type Client interface { - CreateIncidentWithContext(ctx context.Context, from string, options *pagerduty.CreateIncidentOptions) (*pagerduty.Incident, error) + CreateIncidentWithContext(ctx context.Context, from string, options *pagerduty.CreateIncidentOptions) (*pagerduty.Incident, error) //nolint:lll // long line length is acceptable here } // Compile-time check to verify that the PagerDuty type implements the notifier.Notifier interface. @@ -22,7 +23,7 @@ type PagerDuty struct { func New(token string, clientOptions ...pagerduty.ClientOptions) (*PagerDuty, error) { if token == "" { - return nil, fmt.Errorf("access token is required") + return nil, errors.New("access token is required") } pagerDuty := &PagerDuty{ @@ -46,7 +47,7 @@ func (s *PagerDuty) Send(ctx context.Context, subject, message string) error { _, err := s.Client.CreateIncidentWithContext(ctx, s.Config.FromAddress, incident) if err != nil { - return fmt.Errorf("failed to create pager duty incident: %w", err) + return fmt.Errorf("create pager duty incident: %w", err) } } diff --git a/service/pagerduty/pager_duty_test.go b/service/pagerduty/pager_duty_test.go index 23cec5c1..9af9b34e 100644 --- a/service/pagerduty/pager_duty_test.go +++ b/service/pagerduty/pager_duty_test.go @@ -2,7 +2,7 @@ package pagerduty_test import ( "context" - "fmt" + "errors" "testing" gopagerduty "github.com/PagerDuty/go-pagerduty" @@ -29,7 +29,7 @@ func (m *mockClient) CreateIncidentWithContext( incident, isIncident := args.Get(0).(*gopagerduty.Incident) if !isIncident { - return nil, fmt.Errorf("unexpected type for first argument") + return nil, errors.New("unexpected type for first argument") } return incident, nil @@ -89,7 +89,7 @@ func TestPagerDuty_Send(t *testing.T) { message: "Test Message", mockSetup: func(m *mockClient) { m.On("CreateIncidentWithContext", mock.Anything, "sender@domain.com", mock.Anything). - Return(nil, fmt.Errorf("invalid configuration: at least one receiver is required")) + Return(nil, errors.New("invalid configuration: at least one receiver is required")) }, expectedError: "invalid configuration: at least one receiver is required", },