Skip to content

Commit

Permalink
PMM-8019 Fix linters
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov committed Dec 26, 2023
1 parent 5cce687 commit 87cb62e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 22 deletions.
5 changes: 3 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ linters:
enable-all: true
disable:
# keep the rules sorted alpahbetically
- deadcode # unmaintained, we leverage `unused`
- dupl # we can't avoid duplicating code
- execinquery # false positives only
- exhaustivestruct # too annoying
- exhaustruct # too many files to fix/nolint
- deadcode # unmaintained, we leverage `unused`
- dupl # we can't avoid duplicating code
- funlen # useless
- gochecknoglobals # mostly useless
- gochecknoinits # we use init functions
Expand All @@ -100,6 +100,7 @@ linters:
- maligned # deprecated
- nlreturn # too annoying
- nosnakecase # deprecated
- protogetter # we need direct access to proto fields
- rowserrcheck # disabled because of generics
- scopelint # too many false positives
- structcheck # replaced by unused
Expand Down
6 changes: 3 additions & 3 deletions agent/agents/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ func TestCacheErrors(t *testing.T) {
t.Parallel()
var err error
_, err = New(100, time.Second*100, 100, logrus.WithField("test", t.Name()))
assert.NotNil(t, err)
assert.Error(t, err) //nolint:testifylint

_, err = New([]float64{}, time.Second*100, 100, logrus.WithField("test", t.Name()))
assert.NotNil(t, err)
assert.Error(t, err) //nolint:testifylint

_, err = New(struct{}{}, time.Second*100, 100, logrus.WithField("test", t.Name()))
assert.NotNil(t, err)
assert.Error(t, err) //nolint:testifylint
})

t.Run("WrongTypeOnRefresh", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions agent/utils/mongo_fix/mongo_fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func TestClientOptionsForDSN(t *testing.T) {
assert.Equal(t, err.Error(), tt.error)
} else {
assert.Empty(t, err)
assert.Equal(t, got.Auth.Username, tt.expectedUser)
assert.Equal(t, got.Auth.Password, tt.expectedPassword)
assert.Equal(t, tt.expectedUser, got.Auth.Username)
assert.Equal(t, tt.expectedPassword, got.Auth.Password)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion managed/services/inventory/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (ss *ServicesService) List(ctx context.Context, filters models.ServiceFilte
return res, nil
}

// ListActiveServiceTypes lists all active Service Types
// ListActiveServiceTypes lists all active Service Types.
func (ss *ServicesService) ListActiveServiceTypes(ctx context.Context) ([]inventoryv1.ServiceType, error) {
var types []models.ServiceType
e := ss.db.InTransactionContext(ctx, nil, func(tx *reform.TX) error {
Expand Down
12 changes: 6 additions & 6 deletions managed/services/management/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ func TestRoleService(t *testing.T) {

roles, err := s.ListRoles(ctx, &rolev1beta1.ListRolesRequest{})
require.NoError(t, err)
assert.Equal(t, roles.Roles[0].Title, "Role A")
assert.Equal(t, roles.Roles[0].Filter, "filter A")
assert.Equal(t, roles.Roles[0].Description, "Role A description")
assert.Equal(t, roles.Roles[1].Title, "Role B - updated")
assert.Equal(t, roles.Roles[1].Filter, "")
assert.Equal(t, roles.Roles[1].Description, "Role B description")
assert.Equal(t, "Role A", roles.Roles[0].Title)
assert.Equal(t, "filter A", roles.Roles[0].Filter)
assert.Equal(t, "Role A description", roles.Roles[0].Description)
assert.Equal(t, "Role B - updated", roles.Roles[1].Title)
assert.Empty(t, roles.Roles[1].Filter)
assert.Equal(t, "Role B description", roles.Roles[1].Description)
})

t.Run("Shall return not found", func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions managed/services/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func TestServer(t *testing.T) {
"PMM_PUBLIC_ADDRESS=1.2.3.4:5678",
})
require.Empty(t, errs)
assert.Equal(t, true, *s.envSettings.EnableUpdates)
assert.Equal(t, true, *s.envSettings.EnableTelemetry)
assert.True(t, *s.envSettings.EnableUpdates)
assert.True(t, *s.envSettings.EnableTelemetry)
assert.Equal(t, time.Second, s.envSettings.MetricsResolutions.HR)
assert.Equal(t, 2*time.Second, s.envSettings.MetricsResolutions.MR)
assert.Equal(t, 3*time.Second, s.envSettings.MetricsResolutions.LR)
Expand All @@ -117,7 +117,7 @@ func TestServer(t *testing.T) {
"DATA_RETENTION=360H",
})
require.Empty(t, errs)
assert.Equal(t, true, *s.envSettings.EnableTelemetry)
assert.True(t, *s.envSettings.EnableTelemetry)
assert.Equal(t, 3*time.Second, s.envSettings.MetricsResolutions.HR)
assert.Equal(t, 15*24*time.Hour, s.envSettings.DataRetention)
})
Expand Down
7 changes: 4 additions & 3 deletions managed/utils/pprof/pprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestHeap(t *testing.T) {
t.Parallel()
t.Run("Heap test", func(t *testing.T) {
t.Parallel()
heapBytes, err := Heap(true)
assert.NoError(t, err)
require.NoError(t, err)

// read gzip
reader, err := gzip.NewReader(bytes.NewBuffer(heapBytes))
assert.NoError(t, err)
require.NoError(t, err)

var resB bytes.Buffer
_, err = resB.ReadFrom(reader)
assert.NoError(t, err)
require.NoError(t, err)
assert.NotEmpty(t, resB.Bytes())
})
}
Expand Down
4 changes: 2 additions & 2 deletions managed/utils/tests/asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func AssertGRPCError(tb testing.TB, expected *status.Status, actual error) {
return
}
err := s.Err()
if !assert.NotNil(tb, err) {
if assert.NoError(tb, err) { //nolint:testifylint
return
}
assert.Equal(tb, expected.Err().Error(), err.Error()) // gives the best error message
Expand Down Expand Up @@ -61,5 +61,5 @@ func AssertGRPCErrorCode(tb testing.TB, expectedCode codes.Code, actual error) {
return
}

assert.Equal(tb, s.Code(), expectedCode)
assert.Equal(tb, expectedCode, s.Code())
}

0 comments on commit 87cb62e

Please sign in to comment.