Skip to content

Commit 67afab1

Browse files
committed
[chore]: enable len rule from testifylint
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent b4fab2b commit 67afab1

File tree

28 files changed

+101
-81
lines changed

28 files changed

+101
-81
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ linters-settings:
132132
- float-compare
133133
- formatter
134134
- go-require
135-
- len
136135
- negative-positive
137136
- nil-compare
138137
- require-error

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ 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
60+
gotestifylint:
61+
@$(MAKE) for-all-target TARGET="testifylint"
62+
63+
.PHONY: gotestifylint-fix
64+
gotestifylint-fix:
65+
$(MAKE) for-all-target TARGET="testifylint-fix"
66+
5967
.PHONY: goporto
6068
goporto: $(PORTO)
6169
$(PORTO) -w --include-internal --skip-dirs "^cmd/mdatagen/third_party$$" ./

Makefile.Common

Lines changed: 12 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,empty,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,12 @@ impi: $(IMPI)
8891
.PHONY: moddownload
8992
moddownload:
9093
$(GOCMD) mod download
94+
95+
.PHONY: testifylint
96+
testifylint: $(TESTIFYLINT)
97+
@echo "running $(TESTIFYLINT)"
98+
@$(TESTIFYLINT) $(TESTIFYLINT_OPT) ./...
99+
100+
.PHONY: testifylint-fix
101+
testifylint-fix:
102+
@$(MAKE) testifylint TESTIFYLINT_OPT="${TESTIFYLINT_OPT} --fix"

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
}

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.Len(t, sink.AllTraces(), 0)
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.Len(t, sink.AllMetrics(), 0)
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.Len(t, sink.AllLogs(), 0)
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.Len(t, sink.AllProfiles(), 0)
7676
}

exporter/exporterhelper/logs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func checkWrapSpanForLogsExporter(t *testing.T, sr *tracetest.SpanRecorder, trac
418418

419419
// Inspection time!
420420
gotSpanData := sr.Ended()
421-
require.Equal(t, numRequests+1, len(gotSpanData))
421+
require.Len(t, gotSpanData, numRequests+1)
422422

423423
parentSpan := gotSpanData[numRequests]
424424
require.Equalf(t, fakeLogsParentSpanName, parentSpan.Name(), "SpanData %v", parentSpan)

exporter/exporterhelper/metrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func checkWrapSpanForMetricsExporter(t *testing.T, sr *tracetest.SpanRecorder, t
424424

425425
// Inspection time!
426426
gotSpanData := sr.Ended()
427-
require.Equal(t, numRequests+1, len(gotSpanData))
427+
require.Len(t, gotSpanData, numRequests+1)
428428

429429
parentSpan := gotSpanData[numRequests]
430430
require.Equalf(t, fakeMetricsParentSpanName, parentSpan.Name(), "SpanData %v", parentSpan)

exporter/exporterhelper/traces_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func checkWrapSpanForTracesExporter(t *testing.T, sr *tracetest.SpanRecorder, tr
426426

427427
// Inspection time!
428428
gotSpanData := sr.Ended()
429-
require.Equal(t, numRequests+1, len(gotSpanData))
429+
require.Len(t, gotSpanData, numRequests+1)
430430

431431
parentSpan := gotSpanData[numRequests]
432432
require.Equalf(t, fakeTraceParentSpanName, parentSpan.Name(), "SpanData %v", parentSpan)

exporter/otlpexporter/otlp_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func TestSendTraces(t *testing.T) {
300300

301301
md := rcv.getMetadata()
302302
require.EqualValues(t, md.Get("header"), expectedHeader)
303-
require.Equal(t, len(md.Get("User-Agent")), 1)
303+
require.Len(t, md.Get("User-Agent"), 1)
304304
require.Contains(t, md.Get("User-Agent")[0], "Collector/1.2.3test")
305305

306306
// Return partial success
@@ -472,7 +472,7 @@ func TestSendMetrics(t *testing.T) {
472472

473473
mdata := rcv.getMetadata()
474474
require.EqualValues(t, mdata.Get("header"), expectedHeader)
475-
require.Equal(t, len(mdata.Get("User-Agent")), 1)
475+
require.Len(t, mdata.Get("User-Agent"), 1)
476476
require.Contains(t, mdata.Get("User-Agent")[0], "Collector/1.2.3test")
477477

478478
st := status.New(codes.InvalidArgument, "Invalid argument")
@@ -763,7 +763,7 @@ func TestSendLogData(t *testing.T) {
763763
assert.EqualValues(t, ld, rcv.getLastRequest())
764764

765765
md := rcv.getMetadata()
766-
require.Equal(t, len(md.Get("User-Agent")), 1)
766+
require.Len(t, md.Get("User-Agent"), 1)
767767
require.Contains(t, md.Get("User-Agent")[0], "Collector/1.2.3test")
768768

769769
st := status.New(codes.InvalidArgument, "Invalid argument")

extension/ballastextension/memory_ballast_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestMemoryBallast(t *testing.T) {
6262
assert.Nil(t, mbExt.ballast)
6363

6464
assert.NoError(t, mbExt.Start(context.Background(), componenttest.NewNopHost()))
65-
assert.Equal(t, tt.expect, len(mbExt.ballast))
65+
assert.Len(t, mbExt.ballast, tt.expect)
6666

6767
assert.NoError(t, mbExt.Shutdown(context.Background()))
6868
assert.Nil(t, mbExt.ballast)

0 commit comments

Comments
 (0)