From aef9e4fa2fbc2a372b7384b49c83a13c7cfc962e Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Fri, 20 Sep 2024 09:39:27 +0200 Subject: [PATCH] [chore]: enable bool-compare rule from testifylint (#5829) #### Description Testifylint is a linter that provides best practices with the use of testify. This PR enables [bool-compare](https://github.com/Antonboom/testifylint?tab=readme-ov-file#bool-compare) rule from [testifylint](https://github.com/Antonboom/testifylint) It's linter provided by golangci-lint. Here all available rules are activated except those who require to be fixed. This PR only fixes bool-compare so the quantity of changes stays reasonnable for reviewers. Signed-off-by: Matthieu MOREL Co-authored-by: Damien Mathieu <42@dmathieu.com> --- .golangci.yml | 14 ++++++++++++++ .../otlpmetricgrpc/internal/oconf/options_test.go | 12 ++++++------ .../otlpmetrichttp/internal/oconf/options_test.go | 12 ++++++------ .../internal/otlpconfig/options_test.go | 12 ++++++------ .../internal/otlpconfig/options_test.go | 12 ++++++------ .../otlp/otlpmetric/oconf/options_test.go.tmpl | 12 ++++++------ .../otlp/otlptrace/otlpconfig/options_test.go.tmpl | 12 ++++++------ log/keyvalue_test.go | 2 +- 8 files changed, 51 insertions(+), 37 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a5f904197fe..46c52850552 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,6 +25,7 @@ linters: - revive - staticcheck - tenv + - testifylint - typecheck - unconvert - unused @@ -302,3 +303,16 @@ linters-settings: # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#waitgroup-by-value - name: waitgroup-by-value disabled: false + testifylint: + enable-all: true + disable: + - empty + - error-is-as + - error-nil + - expected-actual + - float-compare + - go-require + - len + - negative-positive + - require-error + - suite-extra-assert-call diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go index f5fd29966ba..38fa4be7abd 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go @@ -101,7 +101,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Metrics.Endpoint) assert.Equal(t, "/somepath", c.Metrics.URLPath) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, { @@ -112,7 +112,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Metrics.Endpoint) assert.Equal(t, "/somepath", c.Metrics.URLPath) - assert.Equal(t, false, c.Metrics.Insecure) + assert.False(t, c.Metrics.Insecure) }, }, { @@ -213,7 +213,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Metrics.Endpoint) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, { @@ -223,7 +223,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Metrics.Endpoint) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, { @@ -233,7 +233,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Metrics.Endpoint) - assert.Equal(t, false, c.Metrics.Insecure) + assert.False(t, c.Metrics.Insecure) }, }, { @@ -244,7 +244,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_metrics_endpoint", c.Metrics.Endpoint) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go index 1e44d3e379c..96b1b778362 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go @@ -101,7 +101,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Metrics.Endpoint) assert.Equal(t, "/somepath", c.Metrics.URLPath) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, { @@ -112,7 +112,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Metrics.Endpoint) assert.Equal(t, "/somepath", c.Metrics.URLPath) - assert.Equal(t, false, c.Metrics.Insecure) + assert.False(t, c.Metrics.Insecure) }, }, { @@ -213,7 +213,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Metrics.Endpoint) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, { @@ -223,7 +223,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Metrics.Endpoint) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, { @@ -233,7 +233,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Metrics.Endpoint) - assert.Equal(t, false, c.Metrics.Insecure) + assert.False(t, c.Metrics.Insecure) }, }, { @@ -244,7 +244,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_metrics_endpoint", c.Metrics.Endpoint) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go index 46d0d105fb4..b947ba33ce1 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go @@ -99,7 +99,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Traces.Endpoint) assert.Equal(t, "/somepath", c.Traces.URLPath) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, { @@ -110,7 +110,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Traces.Endpoint) assert.Equal(t, "/somepath", c.Traces.URLPath) - assert.Equal(t, false, c.Traces.Insecure) + assert.False(t, c.Traces.Insecure) }, }, { @@ -211,7 +211,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Traces.Endpoint) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, { @@ -221,7 +221,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Traces.Endpoint) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, { @@ -231,7 +231,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Traces.Endpoint) - assert.Equal(t, false, c.Traces.Insecure) + assert.False(t, c.Traces.Insecure) }, }, { @@ -242,7 +242,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_traces_endpoint", c.Traces.Endpoint) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go index 7ac0711d0eb..89f2c0fd5da 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go @@ -99,7 +99,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Traces.Endpoint) assert.Equal(t, "/somepath", c.Traces.URLPath) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, { @@ -110,7 +110,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Traces.Endpoint) assert.Equal(t, "/somepath", c.Traces.URLPath) - assert.Equal(t, false, c.Traces.Insecure) + assert.False(t, c.Traces.Insecure) }, }, { @@ -211,7 +211,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Traces.Endpoint) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, { @@ -221,7 +221,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Traces.Endpoint) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, { @@ -231,7 +231,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Traces.Endpoint) - assert.Equal(t, false, c.Traces.Insecure) + assert.False(t, c.Traces.Insecure) }, }, { @@ -242,7 +242,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_traces_endpoint", c.Traces.Endpoint) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, diff --git a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl index ac041876fed..6036cd10d4d 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl @@ -101,7 +101,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Metrics.Endpoint) assert.Equal(t, "/somepath", c.Metrics.URLPath) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, { @@ -112,7 +112,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Metrics.Endpoint) assert.Equal(t, "/somepath", c.Metrics.URLPath) - assert.Equal(t, false, c.Metrics.Insecure) + assert.False(t, c.Metrics.Insecure) }, }, { @@ -213,7 +213,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Metrics.Endpoint) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, { @@ -223,7 +223,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Metrics.Endpoint) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, { @@ -233,7 +233,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Metrics.Endpoint) - assert.Equal(t, false, c.Metrics.Insecure) + assert.False(t, c.Metrics.Insecure) }, }, { @@ -244,7 +244,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_metrics_endpoint", c.Metrics.Endpoint) - assert.Equal(t, true, c.Metrics.Insecure) + assert.True(t, c.Metrics.Insecure) }, }, diff --git a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl index 2688db9db51..15cde288583 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl @@ -99,7 +99,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Traces.Endpoint) assert.Equal(t, "/somepath", c.Traces.URLPath) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, { @@ -110,7 +110,7 @@ func TestConfigs(t *testing.T) { asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "someendpoint", c.Traces.Endpoint) assert.Equal(t, "/somepath", c.Traces.URLPath) - assert.Equal(t, false, c.Traces.Insecure) + assert.False(t, c.Traces.Insecure) }, }, { @@ -211,7 +211,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Traces.Endpoint) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, { @@ -221,7 +221,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Traces.Endpoint) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, { @@ -231,7 +231,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_endpoint", c.Traces.Endpoint) - assert.Equal(t, false, c.Traces.Insecure) + assert.False(t, c.Traces.Insecure) }, }, { @@ -242,7 +242,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.Equal(t, "env_traces_endpoint", c.Traces.Endpoint) - assert.Equal(t, true, c.Traces.Insecure) + assert.True(t, c.Traces.Insecure) }, }, diff --git a/log/keyvalue_test.go b/log/keyvalue_test.go index 8b0788ea1dd..4d5afcfa328 100644 --- a/log/keyvalue_test.go +++ b/log/keyvalue_test.go @@ -91,7 +91,7 @@ func TestSortedValueEqual(t *testing.T) { } for _, tc := range testCases { t.Run(tc.value.String(), func(t *testing.T) { - assert.Equal(t, true, tc.value.Equal(tc.value2), "%v.Equal(%v)", tc.value, tc.value2) + assert.True(t, tc.value.Equal(tc.value2), "%v.Equal(%v)", tc.value, tc.value2) }) } }