Skip to content

Commit 6925a30

Browse files
authored
[chore]: enable len and empty rules from testifylint (#11021)
#### Description Testifylint is a linter that provides best practices with the use of testify. This PR enables [len](https://github.com/Antonboom/testifylint?tab=readme-ov-file#len) and [empty](https://github.com/Antonboom/testifylint?tab=readme-ov-file#empty) rules from [testifylint](https://github.com/Antonboom/testifylint) It also adds testifylint as tool to use with a make command Signed-off-by: Matthieu MOREL <[email protected]>
1 parent e599957 commit 6925a30

File tree

37 files changed

+130
-118
lines changed

37 files changed

+130
-118
lines changed

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,12 @@ linters-settings:
125125
# TODO: enable all rules
126126
disable:
127127
- compares
128-
- empty
129128
- error-is-as
130129
- error-nil
131130
- expected-actual
132131
- float-compare
133132
- formatter
134133
- go-require
135-
- len
136134
- negative-positive
137135
- nil-compare
138136
- require-error

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ gotest-with-cover:
5656
@$(MAKE) for-all-target TARGET="test-with-cover"
5757
$(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./coverage.txt
5858

59+
.PHONY: gotestifylint-fix
60+
gotestifylint-fix:
61+
$(MAKE) for-all-target TARGET="testifylint-fix"
62+
5963
.PHONY: goporto
6064
goporto: $(PORTO)
6165
$(PORTO) -w --include-internal --skip-dirs "^cmd/mdatagen/third_party$$" ./

Makefile.Common

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ MULTIMOD := $(TOOLS_BIN_DIR)/multimod
3636
PORTO := $(TOOLS_BIN_DIR)/porto
3737
SEMCONVGEN := $(TOOLS_BIN_DIR)/semconvgen
3838
SEMCONVKIT := $(TOOLS_BIN_DIR)/semconvkit
39+
TESTIFYLINT := $(TOOLS_BIN_DIR)/testifylint
40+
41+
TESTIFYLINT_OPT?= --enable-all --disable=compares,error-is-as,error-nil,expected-actual,float-compare,formatter,go-require,negative-positive,nil-compare,require-error
3942

4043
.PHONY: install-tools
4144
install-tools: $(TOOLS_BIN_NAMES)
@@ -88,3 +91,9 @@ impi: $(IMPI)
8891
.PHONY: moddownload
8992
moddownload:
9093
$(GOCMD) mod download
94+
95+
.PHONY: testifylint-fix
96+
testifylint-fix:$(TESTIFYLINT)
97+
@echo "running $(TESTIFYLINT)"
98+
@$(TESTIFYLINT) $(TESTIFYLINT_OPT) -fix ./...
99+

cmd/builder/internal/builder/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ func TestNewBuiltinConfig(t *testing.T) {
171171
// Unlike the config initialized in NewDefaultConfig(), we expect
172172
// the builtin default to be practically useful, so there must be
173173
// a set of modules present.
174-
assert.NotZero(t, len(cfg.Receivers))
175-
assert.NotZero(t, len(cfg.Exporters))
176-
assert.NotZero(t, len(cfg.Extensions))
177-
assert.NotZero(t, len(cfg.Processors))
174+
assert.NotEmpty(t, cfg.Receivers)
175+
assert.NotEmpty(t, cfg.Exporters)
176+
assert.NotEmpty(t, cfg.Extensions)
177+
assert.NotEmpty(t, cfg.Processors)
178178
}
179179

180180
func TestSkipGoValidation(t *testing.T) {

connector/connectorprofiles/profiles_router_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ func TestProfilessRouterConsumer(t *testing.T) {
120120
assert.Len(t, rcs, 2)
121121
assert.ElementsMatch(t, []component.ID{fooID, barID}, rcs)
122122

123-
assert.Len(t, foo.AllProfiles(), 0)
124-
assert.Len(t, bar.AllProfiles(), 0)
123+
assert.Empty(t, foo.AllProfiles())
124+
assert.Empty(t, bar.AllProfiles())
125125

126126
both, err := r.Consumer(fooID, barID)
127127
assert.NotNil(t, both)

connector/forwardconnector/forward_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestForward(t *testing.T) {
5757
assert.NoError(t, metricsToMetrics.Shutdown(ctx))
5858
assert.NoError(t, logsToLogs.Shutdown(ctx))
5959

60-
assert.Equal(t, 1, len(tracesSink.AllTraces()))
61-
assert.Equal(t, 2, len(metricsSink.AllMetrics()))
62-
assert.Equal(t, 3, len(logsSink.AllLogs()))
60+
assert.Len(t, tracesSink.AllTraces(), 1)
61+
assert.Len(t, metricsSink.AllMetrics(), 2)
62+
assert.Len(t, logsSink.AllLogs(), 3)
6363
}

connector/logs_router_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ func TestLogsRouterConsumers(t *testing.T) {
119119
assert.Len(t, rcs, 2)
120120
assert.ElementsMatch(t, []component.ID{fooID, barID}, rcs)
121121

122-
assert.Len(t, foo.AllLogs(), 0)
123-
assert.Len(t, bar.AllLogs(), 0)
122+
assert.Empty(t, foo.AllLogs())
123+
assert.Empty(t, bar.AllLogs())
124124

125125
both, err := r.Consumer(fooID, barID)
126126
assert.NotNil(t, both)

connector/metrics_router_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ func TestMetricsRouterConsumers(t *testing.T) {
119119
assert.Len(t, rcs, 2)
120120
assert.ElementsMatch(t, []component.ID{fooID, barID}, rcs)
121121

122-
assert.Len(t, foo.AllMetrics(), 0)
123-
assert.Len(t, bar.AllMetrics(), 0)
122+
assert.Empty(t, foo.AllMetrics())
123+
assert.Empty(t, bar.AllMetrics())
124124

125125
both, err := r.Consumer(fooID, barID)
126126
assert.NotNil(t, both)

connector/traces_router_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ func TestTracesRouterConsumer(t *testing.T) {
119119
assert.Len(t, rcs, 2)
120120
assert.ElementsMatch(t, []component.ID{fooID, barID}, rcs)
121121

122-
assert.Len(t, foo.AllTraces(), 0)
123-
assert.Len(t, bar.AllTraces(), 0)
122+
assert.Empty(t, foo.AllTraces())
123+
assert.Empty(t, bar.AllTraces())
124124

125125
both, err := r.Consumer(fooID, barID)
126126
assert.NotNil(t, both)

consumer/consumertest/sink_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestTracesSink(t *testing.T) {
2828
assert.Equal(t, want, sink.AllTraces())
2929
assert.Equal(t, len(want), sink.SpanCount())
3030
sink.Reset()
31-
assert.Equal(t, 0, len(sink.AllTraces()))
31+
assert.Empty(t, sink.AllTraces())
3232
assert.Equal(t, 0, sink.SpanCount())
3333
}
3434

@@ -43,7 +43,7 @@ func TestMetricsSink(t *testing.T) {
4343
assert.Equal(t, want, sink.AllMetrics())
4444
assert.Equal(t, 2*len(want), sink.DataPointCount())
4545
sink.Reset()
46-
assert.Equal(t, 0, len(sink.AllMetrics()))
46+
assert.Empty(t, sink.AllMetrics())
4747
assert.Equal(t, 0, sink.DataPointCount())
4848
}
4949

@@ -58,7 +58,7 @@ func TestLogsSink(t *testing.T) {
5858
assert.Equal(t, want, sink.AllLogs())
5959
assert.Equal(t, len(want), sink.LogRecordCount())
6060
sink.Reset()
61-
assert.Equal(t, 0, len(sink.AllLogs()))
61+
assert.Empty(t, sink.AllLogs())
6262
assert.Equal(t, 0, sink.LogRecordCount())
6363
}
6464

@@ -72,5 +72,5 @@ func TestProfilesSink(t *testing.T) {
7272
}
7373
assert.Equal(t, want, sink.AllProfiles())
7474
sink.Reset()
75-
assert.Equal(t, 0, len(sink.AllProfiles()))
75+
assert.Empty(t, sink.AllProfiles())
7676
}

0 commit comments

Comments
 (0)