From d284a86fa569b58b1bea633fb26aa2ea8931e328 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Wed, 25 Sep 2024 11:07:59 +0200 Subject: [PATCH] [chore]: enable error-nil rule from testifylint (#5843) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Testifylint is a linter that provides best practices with the use of testify. This PR enables [error-nil](https://github.com/Antonboom/testifylint?tab=readme-ov-file#error-nil) rule from [testifylint](https://github.com/Antonboom/testifylint) Signed-off-by: Matthieu MOREL Co-authored-by: Robert PajÄ…k --- .golangci.yml | 1 - bridge/opencensus/metric_test.go | 2 +- .../otlpmetric/otlpmetricgrpc/internal/partialsuccess_test.go | 1 - .../otlpmetricgrpc/internal/transform/error_test.go | 2 +- .../otlpmetric/otlpmetrichttp/internal/partialsuccess_test.go | 1 - .../otlpmetrichttp/internal/transform/error_test.go | 2 +- .../otlptrace/otlptracegrpc/internal/partialsuccess_test.go | 1 - .../otlptrace/otlptracehttp/internal/partialsuccess_test.go | 1 - exporters/stdout/stdouttrace/trace_test.go | 2 +- internal/shared/otlp/otlpmetric/transform/error_test.go.tmpl | 2 +- internal/shared/otlp/partialsuccess_test.go.tmpl | 1 - sdk/metric/config_test.go | 4 ++-- sdk/trace/provider_test.go | 2 +- 13 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 73519fa86b5..ffd12be75bc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -306,7 +306,6 @@ linters-settings: testifylint: enable-all: true disable: - - error-nil - expected-actual - float-compare - go-require diff --git a/bridge/opencensus/metric_test.go b/bridge/opencensus/metric_test.go index e1676b7182f..42ed3d2f9c0 100644 --- a/bridge/opencensus/metric_test.go +++ b/bridge/opencensus/metric_test.go @@ -131,7 +131,7 @@ func TestMetricProducer(t *testing.T) { if tc.expectErr { require.Error(t, err) } else { - require.Nil(t, err) + require.NoError(t, err) } require.Equal(t, len(output), len(tc.expected)) for i := range output { diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/partialsuccess_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/partialsuccess_test.go index b946b0a8215..56cb8b0ff5f 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/partialsuccess_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/partialsuccess_test.go @@ -15,7 +15,6 @@ import ( func requireErrorString(t *testing.T, expect string, err error) { t.Helper() - require.NotNil(t, err) require.Error(t, err) require.ErrorIs(t, err, PartialSuccess{}) diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error_test.go index 1bb250a1a3d..85c8a1b40ab 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error_test.go @@ -35,7 +35,7 @@ func TestMultiErr(t *testing.T) { me := &multiErr{datatype: name} t.Run("ErrOrNil", func(t *testing.T) { - require.Nil(t, me.errOrNil()) + require.NoError(t, me.errOrNil()) me.errs = []error{e0} assert.Error(t, me.errOrNil()) }) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/partialsuccess_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/partialsuccess_test.go index b946b0a8215..56cb8b0ff5f 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/partialsuccess_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/partialsuccess_test.go @@ -15,7 +15,6 @@ import ( func requireErrorString(t *testing.T, expect string, err error) { t.Helper() - require.NotNil(t, err) require.Error(t, err) require.ErrorIs(t, err, PartialSuccess{}) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error_test.go index 1bb250a1a3d..85c8a1b40ab 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error_test.go @@ -35,7 +35,7 @@ func TestMultiErr(t *testing.T) { me := &multiErr{datatype: name} t.Run("ErrOrNil", func(t *testing.T) { - require.Nil(t, me.errOrNil()) + require.NoError(t, me.errOrNil()) me.errs = []error{e0} assert.Error(t, me.errOrNil()) }) diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/partialsuccess_test.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/partialsuccess_test.go index b946b0a8215..56cb8b0ff5f 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/partialsuccess_test.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/partialsuccess_test.go @@ -15,7 +15,6 @@ import ( func requireErrorString(t *testing.T, expect string, err error) { t.Helper() - require.NotNil(t, err) require.Error(t, err) require.ErrorIs(t, err, PartialSuccess{}) diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/partialsuccess_test.go b/exporters/otlp/otlptrace/otlptracehttp/internal/partialsuccess_test.go index b946b0a8215..56cb8b0ff5f 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/partialsuccess_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/partialsuccess_test.go @@ -15,7 +15,6 @@ import ( func requireErrorString(t *testing.T, expect string, err error) { t.Helper() - require.NotNil(t, err) require.Error(t, err) require.ErrorIs(t, err, PartialSuccess{}) diff --git a/exporters/stdout/stdouttrace/trace_test.go b/exporters/stdout/stdouttrace/trace_test.go index d598ca4cd85..8c3b868c96a 100644 --- a/exporters/stdout/stdouttrace/trace_test.go +++ b/exporters/stdout/stdouttrace/trace_test.go @@ -88,7 +88,7 @@ func TestExporterExportSpan(t *testing.T) { // write to buffer for testing var b bytes.Buffer ex, err := stdouttrace.New(append(tt.opts, stdouttrace.WithWriter(&b))...) - require.Nil(t, err) + require.NoError(t, err) err = ex.ExportSpans(tt.ctx, tracetest.SpanStubs{ss, ss}.Snapshots()) assert.Equal(t, tt.wantErr, err) diff --git a/internal/shared/otlp/otlpmetric/transform/error_test.go.tmpl b/internal/shared/otlp/otlpmetric/transform/error_test.go.tmpl index 1bb250a1a3d..85c8a1b40ab 100644 --- a/internal/shared/otlp/otlpmetric/transform/error_test.go.tmpl +++ b/internal/shared/otlp/otlpmetric/transform/error_test.go.tmpl @@ -35,7 +35,7 @@ func TestMultiErr(t *testing.T) { me := &multiErr{datatype: name} t.Run("ErrOrNil", func(t *testing.T) { - require.Nil(t, me.errOrNil()) + require.NoError(t, me.errOrNil()) me.errs = []error{e0} assert.Error(t, me.errOrNil()) }) diff --git a/internal/shared/otlp/partialsuccess_test.go.tmpl b/internal/shared/otlp/partialsuccess_test.go.tmpl index b946b0a8215..56cb8b0ff5f 100644 --- a/internal/shared/otlp/partialsuccess_test.go.tmpl +++ b/internal/shared/otlp/partialsuccess_test.go.tmpl @@ -15,7 +15,6 @@ import ( func requireErrorString(t *testing.T, expect string, err error) { t.Helper() - require.NotNil(t, err) require.Error(t, err) require.ErrorIs(t, err, PartialSuccess{}) diff --git a/sdk/metric/config_test.go b/sdk/metric/config_test.go index 032337cefe7..d3c1341bf51 100644 --- a/sdk/metric/config_test.go +++ b/sdk/metric/config_test.go @@ -55,8 +55,8 @@ func TestConfigReaderSignalsEmpty(t *testing.T) { require.NotNil(t, s) ctx := context.Background() - assert.Nil(t, f(ctx)) - assert.Nil(t, s(ctx)) + assert.NoError(t, f(ctx)) + assert.NoError(t, s(ctx)) assert.ErrorIs(t, s(ctx), ErrReaderShutdown) } diff --git a/sdk/trace/provider_test.go b/sdk/trace/provider_test.go index 0c6e2f7dc88..3644e377316 100644 --- a/sdk/trace/provider_test.go +++ b/sdk/trace/provider_test.go @@ -370,7 +370,7 @@ func testStoredError(t *testing.T, target interface{}) { err := handler.errs[0] require.Implements(t, (*error)(nil), target) - require.NotNil(t, target.(error)) + require.Error(t, target.(error)) defer handler.Reset() if errors.Is(err, target.(error)) {