Skip to content

Commit

Permalink
fixed format (linter)
Browse files Browse the repository at this point in the history
  • Loading branch information
tecnologer committed Jan 13, 2025
1 parent ecd9ac7 commit 309cfa5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 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
21 changes: 10 additions & 11 deletions service/pagerduty/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pagerduty_test

import (
"fmt"
"testing"

gopagerduty "github.com/PagerDuty/go-pagerduty"
Expand All @@ -23,13 +22,13 @@ func TestConfig_NewConfig(t *testing.T) {
require.Equal(t, want, config)
}

func TestConfig_OK(t *testing.T) {
func TestConfig_OK(t *testing.T) { //nolint:funlen

Check failure on line 25 in service/pagerduty/config_test.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:funlen` is unused for linter "funlen" (nolintlint)
t.Parallel()

tests := []struct {
name string
config *pagerduty.Config
wantErr error
wantErr string
}{
{
name: "ok_basic_config",
Expand All @@ -38,7 +37,7 @@ func TestConfig_OK(t *testing.T) {
Receivers: []string{"AB1234", "CD5678"},
NotificationType: "incident",
},
wantErr: nil,
wantErr: "",
},
{
name: "ok_complete_config",
Expand All @@ -49,37 +48,37 @@ func TestConfig_OK(t *testing.T) {
PriorityID: "P1234",
NotificationType: "incident",
},
wantErr: nil,
wantErr: "",
},
{
name: "missing_from_address",
config: &pagerduty.Config{
Receivers: []string{"AB1234", "CD5678"},
},
wantErr: fmt.Errorf("from address is required"),
wantErr: "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: "from address is invalid: mail: missing '@' or angle-addr",
},
{
name: "missing_receivers",
config: &pagerduty.Config{
FromAddress: "[email protected]",
},
wantErr: fmt.Errorf("at least one receiver is required"),
wantErr: "at least one receiver is required",
},
{
name: "missing_notification_type",
config: &pagerduty.Config{
FromAddress: "[email protected]",
Receivers: []string{"AB1234", "CD5678"},
},
wantErr: fmt.Errorf("notification type is required"),
wantErr: "notification type is required",
},
}

Expand All @@ -88,12 +87,12 @@ func TestConfig_OK(t *testing.T) {
t.Parallel()

err := test.config.OK()
if test.wantErr == nil {
if test.wantErr == "" {
require.NoError(t, err)
return
}

require.EqualError(t, err, test.wantErr.Error())
require.EqualError(t, err, test.wantErr)
})
}
}
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 // acceptable in this case, alternative makes the interface even less readable
}

// 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")
}

Check warning on line 27 in service/pagerduty/pager_duty.go

View check run for this annotation

Codecov / codecov/patch

service/pagerduty/pager_duty.go#L26-L27

Added lines #L26 - L27 were not covered by tests

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)
}

Check warning on line 51 in service/pagerduty/pager_duty.go

View check run for this annotation

Codecov / codecov/patch

service/pagerduty/pager_duty.go#L50-L51

Added lines #L50 - L51 were not covered by tests
}

Expand Down
8 changes: 4 additions & 4 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 All @@ -49,7 +49,7 @@ func TestPagerDuty_New(t *testing.T) {
assert.Equal(t, want, service)
}

func TestPagerDuty_Send(t *testing.T) {
func TestPagerDuty_Send(t *testing.T) { //nolint:funlen

Check failure on line 52 in service/pagerduty/pager_duty_test.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:funlen` is unused for linter "funlen" (nolintlint)
t.Parallel()

tests := []struct {
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, "[email protected]", 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 309cfa5

Please sign in to comment.