Skip to content

Commit

Permalink
chore(pager_duty): fix linter complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoksr committed Jan 12, 2025
1 parent ecd9ac7 commit 72487c6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
7 changes: 4 additions & 3 deletions service/pagerduty/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pagerduty

import (
"errors"
"fmt"
"net/mail"

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions service/pagerduty/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pagerduty_test

import (
"fmt"
"errors"
"testing"

gopagerduty "github.com/PagerDuty/go-pagerduty"
Expand Down Expand Up @@ -56,30 +56,30 @@ 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",
config: &pagerduty.Config{
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",
config: &pagerduty.Config{
FromAddress: "sender@domain.com",
Receivers: []string{"AB1234", "CD5678"},
},
wantErr: fmt.Errorf("notification type is required"),
wantErr: errors.New("notification type is required"),
},
}

Expand Down
7 changes: 4 additions & 3 deletions service/pagerduty/pager_duty.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package pagerduty

import (
"context"
"errors"
"fmt"

"github.com/PagerDuty/go-pagerduty"
"github.com/nikoksr/notify"
)

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.
Expand All @@ -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{
Expand All @@ -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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions service/pagerduty/pager_duty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pagerduty_test

import (
"context"
"fmt"
"errors"
"testing"

gopagerduty "github.com/PagerDuty/go-pagerduty"
Expand All @@ -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
Expand Down Expand Up @@ -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",
},
Expand Down

0 comments on commit 72487c6

Please sign in to comment.