Skip to content

Commit eb0a4b6

Browse files
authored
[chore]: enable expected-actual rule from testifylint (#11135)
#### Description Testifylint is a linter that provides best practices with the use of testify. This PR enables [expected-actual](https://github.com/Antonboom/testifylint?tab=readme-ov-file#expected-actual) rule from [testifylint](https://github.com/Antonboom/testifylint) Signed-off-by: Matthieu MOREL <[email protected]>
1 parent feb41fe commit eb0a4b6

File tree

24 files changed

+118
-120
lines changed

24 files changed

+118
-120
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ linters-settings:
125125
# TODO: enable all rules
126126
disable:
127127
- error-is-as
128-
- expected-actual
129128
- float-compare
130129
- formatter
131130
- go-require

Makefile.Common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ SEMCONVGEN := $(TOOLS_BIN_DIR)/semconvgen
3838
SEMCONVKIT := $(TOOLS_BIN_DIR)/semconvkit
3939
TESTIFYLINT := $(TOOLS_BIN_DIR)/testifylint
4040

41-
TESTIFYLINT_OPT?= --enable-all --disable=error-is-as,expected-actual,float-compare,formatter,go-require,require-error
41+
TESTIFYLINT_OPT?= --enable-all --disable=error-is-as,float-compare,formatter,go-require,require-error
4242

4343
.PHONY: install-tools
4444
install-tools: $(TOOLS_BIN_NAMES)

client/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestFromContext(t *testing.T) {
7171
}
7272
for _, tC := range testCases {
7373
t.Run(tC.desc, func(t *testing.T) {
74-
assert.Equal(t, FromContext(tC.input), tC.expected)
74+
assert.Equal(t, tC.expected, FromContext(tC.input))
7575
})
7676
}
7777
}

component/componenttest/nop_telemetry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ func TestNewNopTelemetrySettings(t *testing.T) {
2323
nts.MeterProvider.Meter("test")
2424
})
2525
assert.Equal(t, configtelemetry.LevelNone, nts.MetricsLevel)
26-
assert.Equal(t, nts.Resource.Attributes().Len(), 0)
26+
assert.Equal(t, 0, nts.Resource.Attributes().Len())
2727
}

config/confighttp/confighttp_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,8 +1249,8 @@ func TestFailedServerAuth(t *testing.T) {
12491249
srv.Handler.ServeHTTP(response, httptest.NewRequest("GET", "/", nil))
12501250

12511251
// verify
1252-
assert.Equal(t, response.Result().StatusCode, http.StatusUnauthorized)
1253-
assert.Equal(t, response.Result().Status, fmt.Sprintf("%v %s", http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized)))
1252+
assert.Equal(t, http.StatusUnauthorized, response.Result().StatusCode)
1253+
assert.Equal(t, fmt.Sprintf("%v %s", http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized)), response.Result().Status)
12541254
}
12551255

12561256
func TestServerWithErrorHandler(t *testing.T) {
@@ -1259,7 +1259,7 @@ func TestServerWithErrorHandler(t *testing.T) {
12591259
Endpoint: "localhost:0",
12601260
}
12611261
eh := func(w http.ResponseWriter, _ *http.Request, _ string, statusCode int) {
1262-
assert.Equal(t, statusCode, http.StatusBadRequest)
1262+
assert.Equal(t, http.StatusBadRequest, statusCode)
12631263
// custom error handler changes returned status code
12641264
http.Error(w, "invalid request", http.StatusInternalServerError)
12651265
}
@@ -1281,7 +1281,7 @@ func TestServerWithErrorHandler(t *testing.T) {
12811281

12821282
srv.Handler.ServeHTTP(response, req)
12831283
// verify
1284-
assert.Equal(t, response.Result().StatusCode, http.StatusInternalServerError)
1284+
assert.Equal(t, http.StatusInternalServerError, response.Result().StatusCode)
12851285
}
12861286

12871287
func TestServerWithDecoder(t *testing.T) {
@@ -1309,7 +1309,7 @@ func TestServerWithDecoder(t *testing.T) {
13091309

13101310
srv.Handler.ServeHTTP(response, req)
13111311
// verify
1312-
assert.Equal(t, response.Result().StatusCode, http.StatusOK)
1312+
assert.Equal(t, http.StatusOK, response.Result().StatusCode)
13131313

13141314
}
13151315

@@ -1356,7 +1356,7 @@ func TestServerWithDecompression(t *testing.T) {
13561356

13571357
// verifications is done mostly within the test, but this is only a sanity check
13581358
// that we got into the test handler
1359-
assert.Equal(t, resp.StatusCode, http.StatusBadRequest)
1359+
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
13601360
}
13611361

13621362
func TestDefaultMaxRequestBodySize(t *testing.T) {

confmap/internal/e2e/types_test.go

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -419,43 +419,42 @@ func TestIssue10787(t *testing.T) {
419419
resolver := NewResolver(t, "issue-10787-main.yaml")
420420
conf, err := resolver.Resolve(context.Background())
421421
require.NoError(t, err)
422-
assert.Equal(t, conf.ToStringMap(),
423-
map[string]any{
424-
"exporters": map[string]any{
425-
"debug": map[string]any{
426-
"verbosity": "detailed",
427-
},
428-
},
429-
"processors": map[string]any{
430-
"batch": nil,
422+
assert.Equal(t, map[string]any{
423+
"exporters": map[string]any{
424+
"debug": map[string]any{
425+
"verbosity": "detailed",
431426
},
432-
"receivers": map[string]any{
433-
"otlp": map[string]any{
434-
"protocols": map[string]any{
435-
"grpc": map[string]any{
436-
"endpoint": "0.0.0.0:4317",
437-
},
438-
"http": map[string]any{
439-
"endpoint": "0.0.0.0:4318",
440-
},
427+
},
428+
"processors": map[string]any{
429+
"batch": nil,
430+
},
431+
"receivers": map[string]any{
432+
"otlp": map[string]any{
433+
"protocols": map[string]any{
434+
"grpc": map[string]any{
435+
"endpoint": "0.0.0.0:4317",
436+
},
437+
"http": map[string]any{
438+
"endpoint": "0.0.0.0:4318",
441439
},
442440
},
443441
},
444-
"service": map[string]any{
445-
"pipelines": map[string]any{
446-
"traces": map[string]any{
447-
"exporters": []any{"debug"},
448-
"processors": []any{"batch"},
449-
"receivers": []any{"otlp"},
450-
},
442+
},
443+
"service": map[string]any{
444+
"pipelines": map[string]any{
445+
"traces": map[string]any{
446+
"exporters": []any{"debug"},
447+
"processors": []any{"batch"},
448+
"receivers": []any{"otlp"},
451449
},
452-
"telemetry": map[string]any{
453-
"metrics": map[string]any{
454-
"level": "detailed",
455-
},
450+
},
451+
"telemetry": map[string]any{
452+
"metrics": map[string]any{
453+
"level": "detailed",
456454
},
457455
},
458456
},
457+
}, conf.ToStringMap(),
459458
)
460459
}
461460

@@ -582,9 +581,9 @@ func TestIndirectSliceEnvVar(t *testing.T) {
582581
var collectorConf CollectorConf
583582
err = conf.Unmarshal(&collectorConf)
584583
require.NoError(t, err)
585-
assert.Equal(t, collectorConf.Exporters.OTLP.Endpoint, "localhost:4317")
586-
assert.Equal(t, collectorConf.Service.Pipelines.Logs.Receivers, []string{"nop", "otlp"})
587-
assert.Equal(t, collectorConf.Service.Pipelines.Logs.Exporters, []string{"otlp", "nop"})
584+
assert.Equal(t, "localhost:4317", collectorConf.Exporters.OTLP.Endpoint)
585+
assert.Equal(t, []string{"nop", "otlp"}, collectorConf.Service.Pipelines.Logs.Receivers)
586+
assert.Equal(t, []string{"otlp", "nop"}, collectorConf.Service.Pipelines.Logs.Exporters)
588587
}
589588

590589
func TestIssue10937_MapType(t *testing.T) {

exporter/debugexporter/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func Test_UnmarshalMarshalled(t *testing.T) {
9494

9595
if tc.expectedErr == "" {
9696
assert.NoError(t, err)
97-
assert.Equal(t, outCfg, tc.expectedConfig)
97+
assert.Equal(t, tc.expectedConfig, outCfg)
9898
return
9999
}
100100
assert.Error(t, err)

exporter/exporterhelper/logs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func TestLogsExporter_WithShutdown_ReturnError(t *testing.T) {
359359
assert.NotNil(t, le)
360360
assert.NoError(t, err)
361361

362-
assert.Equal(t, le.Shutdown(context.Background()), want)
362+
assert.Equal(t, want, le.Shutdown(context.Background()))
363363
}
364364

365365
func TestLogsRequestExporter_WithShutdown_ReturnError(t *testing.T) {
@@ -371,7 +371,7 @@ func TestLogsRequestExporter_WithShutdown_ReturnError(t *testing.T) {
371371
assert.NotNil(t, le)
372372
assert.NoError(t, err)
373373

374-
assert.Equal(t, le.Shutdown(context.Background()), want)
374+
assert.Equal(t, want, le.Shutdown(context.Background()))
375375
}
376376

377377
func newPushLogsDataModifiedDownstream(retError error) consumer.ConsumeLogsFunc {

exporter/exporterhelper/traces_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func TestTracesExporter_WithShutdown_ReturnError(t *testing.T) {
365365
assert.NoError(t, err)
366366

367367
assert.NoError(t, te.Start(context.Background(), componenttest.NewNopHost()))
368-
assert.Equal(t, te.Shutdown(context.Background()), want)
368+
assert.Equal(t, want, te.Shutdown(context.Background()))
369369
}
370370

371371
func TestTracesRequestExporter_WithShutdown_ReturnError(t *testing.T) {
@@ -378,7 +378,7 @@ func TestTracesRequestExporter_WithShutdown_ReturnError(t *testing.T) {
378378
assert.NoError(t, err)
379379

380380
assert.NoError(t, te.Start(context.Background(), componenttest.NewNopHost()))
381-
assert.Equal(t, te.Shutdown(context.Background()), want)
381+
assert.Equal(t, want, te.Shutdown(context.Background()))
382382
}
383383

384384
func newTraceDataPusher(retError error) consumer.ConsumeTracesFunc {

exporter/exportertest/contract_checker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ func checkLogs(t *testing.T, params CheckConsumeContractParams, mockReceiver com
228228
// Test is successful if all the elements were received successfully and no error was returned
229229
func alwaysSucceedsPassed(t *testing.T, allRecordsNumber int, reqCounter requestCounter) {
230230
require.Equal(t, allRecordsNumber, reqCounter.success)
231-
require.Equal(t, reqCounter.total, allRecordsNumber)
232-
require.Equal(t, reqCounter.error.nonpermanent, 0)
233-
require.Equal(t, reqCounter.error.permanent, 0)
231+
require.Equal(t, allRecordsNumber, reqCounter.total)
232+
require.Equal(t, 0, reqCounter.error.nonpermanent)
233+
require.Equal(t, 0, reqCounter.error.permanent)
234234
}
235235

236236
// Test is successful if all the elements were retried on non-permanent errors

0 commit comments

Comments
 (0)