diff --git a/.golangci.yml b/.golangci.yml index a36a87a56f..b1b3db9ab7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 @@ -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 diff --git a/agent/agents/cache/cache_test.go b/agent/agents/cache/cache_test.go index 6299f736bb..7b90eaca70 100644 --- a/agent/agents/cache/cache_test.go +++ b/agent/agents/cache/cache_test.go @@ -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) { diff --git a/agent/utils/mongo_fix/mongo_fix_test.go b/agent/utils/mongo_fix/mongo_fix_test.go index 146a6135de..24afab1a7e 100644 --- a/agent/utils/mongo_fix/mongo_fix_test.go +++ b/agent/utils/mongo_fix/mongo_fix_test.go @@ -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) } }) } diff --git a/managed/services/inventory/services.go b/managed/services/inventory/services.go index 8c642ad2fa..282ccc4c11 100644 --- a/managed/services/inventory/services.go +++ b/managed/services/inventory/services.go @@ -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 { diff --git a/managed/services/management/role_test.go b/managed/services/management/role_test.go index 2db7886db7..b5a66179a4 100644 --- a/managed/services/management/role_test.go +++ b/managed/services/management/role_test.go @@ -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) { diff --git a/managed/services/server/server_test.go b/managed/services/server/server_test.go index 2807a0d096..da85f5f791 100644 --- a/managed/services/server/server_test.go +++ b/managed/services/server/server_test.go @@ -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) @@ -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) }) diff --git a/managed/utils/pprof/pprof_test.go b/managed/utils/pprof/pprof_test.go index 1dcc59a4ba..5b1e53e546 100644 --- a/managed/utils/pprof/pprof_test.go +++ b/managed/utils/pprof/pprof_test.go @@ -23,6 +23,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestHeap(t *testing.T) { @@ -30,15 +31,15 @@ func TestHeap(t *testing.T) { 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()) }) } diff --git a/managed/utils/tests/asserts.go b/managed/utils/tests/asserts.go index cb52d9296a..9471816420 100644 --- a/managed/utils/tests/asserts.go +++ b/managed/utils/tests/asserts.go @@ -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 @@ -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()) }