Skip to content

Commit

Permalink
[chore]: enable expected-actual rule from testifylint (#34998)
Browse files Browse the repository at this point in the history
#### 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 <matthieu.morel35@gmail.com>
Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
  • Loading branch information
mmorel-35 and codeboten authored Sep 5, 2024
1 parent 52b6807 commit 145145c
Show file tree
Hide file tree
Showing 164 changed files with 564 additions and 575 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ linters-settings:

testifylint:
disable:
- expected-actual
- float-compare
- formatter
- go-require
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ GOTESTSUM := $(TOOLS_BIN_DIR)/gotestsum
TESTIFYLINT := $(TOOLS_BIN_DIR)/testifylint

GOTESTSUM_OPT?= --rerun-fails=1
TESTIFYLINT_OPT?= --enable-all --disable=expected-actual,float-compare,formatter,go-require,negative-positive,require-error,suite-dont-use-pkg,suite-subtest-run,useless-assert
TESTIFYLINT_OPT?= --enable-all --disable=float-compare,formatter,go-require,negative-positive,require-error,suite-dont-use-pkg,suite-subtest-run,useless-assert

# BUILD_TYPE should be one of (dev, release).
BUILD_TYPE?=release
Expand Down
2 changes: 1 addition & 1 deletion cmd/telemetrygen/internal/logs/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestLogsWithOneTelemetryAttributes(t *testing.T) {

l.WalkAttributes(func(attr log.KeyValue) bool {
if attr.Key == telemetryAttrKeyOne {
assert.EqualValues(t, attr.Value.AsString(), telemetryAttrValueOne)
assert.EqualValues(t, telemetryAttrValueOne, attr.Value.AsString())
}
return true
})
Expand Down
4 changes: 2 additions & 2 deletions cmd/telemetrygen/internal/metrics/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func TestSumSingleTelemetryAttr(t *testing.T) {
attr := ms.Data.(metricdata.Sum[int64]).DataPoints[0].Attributes
assert.Equal(t, 1, attr.Len(), "it must have a single attribute here")
actualValue, _ := attr.Value(telemetryAttrKeyOne)
assert.Equal(t, actualValue.AsString(), telemetryAttrValueOne, "it should be "+telemetryAttrValueOne)
assert.Equal(t, telemetryAttrValueOne, actualValue.AsString(), "it should be "+telemetryAttrValueOne)
}
}

Expand Down Expand Up @@ -232,7 +232,7 @@ func TestGaugeSingleTelemetryAttr(t *testing.T) {
attr := ms.Data.(metricdata.Gauge[int64]).DataPoints[0].Attributes
assert.Equal(t, 1, attr.Len(), "it must have a single attribute here")
actualValue, _ := attr.Value(telemetryAttrKeyOne)
assert.Equal(t, actualValue.AsString(), telemetryAttrValueOne, "it should be "+telemetryAttrValueOne)
assert.Equal(t, telemetryAttrValueOne, actualValue.AsString(), "it should be "+telemetryAttrValueOne)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/telemetrygen/internal/traces/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestSpanKind(t *testing.T) {

// verify that the default Span Kind is being overridden
for _, span := range syncer.spans {
assert.NotEqual(t, span.SpanKind(), trace.SpanKindInternal)
assert.NotEqual(t, trace.SpanKindInternal, span.SpanKind())
}
}

Expand Down
6 changes: 3 additions & 3 deletions connector/failoverconnector/failover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestFailoverRecovery(t *testing.T) {

require.NoError(t, conn.ConsumeTraces(context.Background(), tr))
idx := failoverConnector.failover.pS.TestStableIndex()
require.Equal(t, idx, 1)
require.Equal(t, 1, idx)

failoverConnector.failover.ModifyConsumerAtIndex(0, &sinkFirst)

Expand All @@ -75,7 +75,7 @@ func TestFailoverRecovery(t *testing.T) {

require.NoError(t, conn.ConsumeTraces(context.Background(), tr))
idx := failoverConnector.failover.pS.TestStableIndex()
require.Equal(t, idx, 1)
require.Equal(t, 1, idx)

failoverConnector.failover.ModifyConsumerAtIndex(0, &sinkFirst)

Expand All @@ -97,7 +97,7 @@ func TestFailoverRecovery(t *testing.T) {

require.NoError(t, conn.ConsumeTraces(context.Background(), tr))
idx := failoverConnector.failover.pS.TestStableIndex()
require.Equal(t, idx, 2)
require.Equal(t, 2, idx)

// Simulate recovery of exporter
failoverConnector.failover.ModifyConsumerAtIndex(1, &sinkSecond)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func TestSelectPipeline(t *testing.T) {

idx, ch := pS.SelectedPipeline()

require.Equal(t, idx, 0)
require.Equal(t, pS.ChannelIndex(ch), 0)
require.Equal(t, 0, idx)
require.Equal(t, 0, pS.ChannelIndex(ch))
}

func TestHandlePipelineError(t *testing.T) {
Expand All @@ -44,7 +44,7 @@ func TestHandlePipelineError(t *testing.T) {
}()

idx, ch := pS.SelectedPipeline()
require.Equal(t, idx, 0)
require.Equal(t, 0, idx)
ch <- false

require.Eventually(t, func() bool {
Expand Down
18 changes: 9 additions & 9 deletions connector/routingconnector/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func TestLogsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllLogs(), 1)
assert.Len(t, sink1.AllLogs(), 1)

assert.Equal(t, sink0.AllLogs()[0].LogRecordCount(), 2)
assert.Equal(t, sink1.AllLogs()[0].LogRecordCount(), 2)
assert.Equal(t, 2, sink0.AllLogs()[0].LogRecordCount())
assert.Equal(t, 2, sink1.AllLogs()[0].LogRecordCount())
assert.Equal(t, sink0.AllLogs(), sink1.AllLogs())
})

Expand Down Expand Up @@ -206,7 +206,7 @@ func TestLogsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {
rlog := defaultSink.AllLogs()[0].ResourceLogs().At(0)
attr, ok := rlog.Resource().Attributes().Get("X-Tenant")
assert.True(t, ok, "routing attribute must exists")
assert.Equal(t, attr.AsString(), "something-else")
assert.Equal(t, "something-else", attr.AsString())
})

t.Run("logs matched by one expression, multiple pipelines", func(t *testing.T) {
Expand All @@ -224,8 +224,8 @@ func TestLogsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllLogs(), 1)
assert.Empty(t, sink1.AllLogs())

assert.Equal(t, defaultSink.AllLogs()[0].LogRecordCount(), 1)
assert.Equal(t, sink0.AllLogs()[0].LogRecordCount(), 1)
assert.Equal(t, 1, defaultSink.AllLogs()[0].LogRecordCount())
assert.Equal(t, 1, sink0.AllLogs()[0].LogRecordCount())
assert.Equal(t, defaultSink.AllLogs(), sink0.AllLogs())
})
}
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestLogsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllLogs(), 1)
assert.Empty(t, sink1.AllLogs())

assert.Equal(t, sink0.AllLogs()[0].LogRecordCount(), 2)
assert.Equal(t, 2, sink0.AllLogs()[0].LogRecordCount())
})

t.Run("one log matched by multiple expressions, other matched none", func(t *testing.T) {
Expand All @@ -358,7 +358,7 @@ func TestLogsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {
rlog := defaultSink.AllLogs()[0].ResourceLogs().At(0)
attr, ok := rlog.Resource().Attributes().Get("X-Tenant")
assert.True(t, ok, "routing attribute must exists")
assert.Equal(t, attr.AsString(), "something-else")
assert.Equal(t, "something-else", attr.AsString())
})

t.Run("logs matched by one expression, multiple pipelines", func(t *testing.T) {
Expand All @@ -376,8 +376,8 @@ func TestLogsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllLogs(), 1)
assert.Empty(t, sink1.AllLogs())

assert.Equal(t, defaultSink.AllLogs()[0].LogRecordCount(), 1)
assert.Equal(t, sink0.AllLogs()[0].LogRecordCount(), 1)
assert.Equal(t, 1, defaultSink.AllLogs()[0].LogRecordCount())
assert.Equal(t, 1, sink0.AllLogs()[0].LogRecordCount())
assert.Equal(t, defaultSink.AllLogs(), sink0.AllLogs())
})
}
Expand Down
14 changes: 7 additions & 7 deletions connector/routingconnector/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func TestMetricsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllMetrics(), 1)
assert.Len(t, sink1.AllMetrics(), 1)

assert.Equal(t, sink0.AllMetrics()[0].MetricCount(), 2)
assert.Equal(t, sink1.AllMetrics()[0].MetricCount(), 2)
assert.Equal(t, 2, sink0.AllMetrics()[0].MetricCount())
assert.Equal(t, 2, sink1.AllMetrics()[0].MetricCount())
assert.Equal(t, sink0.AllMetrics(), sink1.AllMetrics())
})

Expand Down Expand Up @@ -239,8 +239,8 @@ func TestMetricsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllMetrics(), 1)
assert.Empty(t, sink1.AllMetrics())

assert.Equal(t, defaultSink.AllMetrics()[0].MetricCount(), 1)
assert.Equal(t, sink0.AllMetrics()[0].MetricCount(), 1)
assert.Equal(t, 1, defaultSink.AllMetrics()[0].MetricCount())
assert.Equal(t, 1, sink0.AllMetrics()[0].MetricCount())
assert.Equal(t, defaultSink.AllMetrics(), sink0.AllMetrics())
})
}
Expand Down Expand Up @@ -357,7 +357,7 @@ func TestMetricsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllMetrics(), 1)
assert.Empty(t, sink1.AllMetrics())

assert.Equal(t, sink0.AllMetrics()[0].MetricCount(), 2)
assert.Equal(t, 2, sink0.AllMetrics()[0].MetricCount())
})

t.Run("one metric matched by 2 expressions, others matched by none", func(t *testing.T) {
Expand Down Expand Up @@ -406,8 +406,8 @@ func TestMetricsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllMetrics(), 1)
assert.Empty(t, sink1.AllMetrics())

assert.Equal(t, defaultSink.AllMetrics()[0].MetricCount(), 1)
assert.Equal(t, sink0.AllMetrics()[0].MetricCount(), 1)
assert.Equal(t, 1, defaultSink.AllMetrics()[0].MetricCount())
assert.Equal(t, 1, sink0.AllMetrics()[0].MetricCount())
assert.Equal(t, defaultSink.AllMetrics(), sink0.AllMetrics())
})
}
Expand Down
14 changes: 7 additions & 7 deletions connector/routingconnector/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func TestTracesCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllTraces(), 1)
assert.Len(t, sink1.AllTraces(), 1)

assert.Equal(t, sink0.AllTraces()[0].SpanCount(), 2)
assert.Equal(t, sink1.AllTraces()[0].SpanCount(), 2)
assert.Equal(t, 2, sink0.AllTraces()[0].SpanCount())
assert.Equal(t, 2, sink1.AllTraces()[0].SpanCount())
assert.Equal(t, sink0.AllTraces(), sink1.AllTraces())
})

Expand All @@ -199,8 +199,8 @@ func TestTracesCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllTraces(), 1)
assert.Empty(t, sink1.AllTraces())

assert.Equal(t, defaultSink.AllTraces()[0].SpanCount(), 1)
assert.Equal(t, sink0.AllTraces()[0].SpanCount(), 1)
assert.Equal(t, 1, defaultSink.AllTraces()[0].SpanCount())
assert.Equal(t, 1, sink0.AllTraces()[0].SpanCount())
assert.Equal(t, defaultSink.AllTraces(), sink0.AllTraces())
})
}
Expand Down Expand Up @@ -310,7 +310,7 @@ func TestTracesCorrectlyMatchOnceWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllTraces(), 1)
assert.Empty(t, sink1.AllTraces())

assert.Equal(t, sink0.AllTraces()[0].SpanCount(), 2)
assert.Equal(t, 2, sink0.AllTraces()[0].SpanCount())
})

t.Run("span matched by one expression, multiple pipelines", func(t *testing.T) {
Expand All @@ -328,8 +328,8 @@ func TestTracesCorrectlyMatchOnceWithOTTL(t *testing.T) {
assert.Len(t, sink0.AllTraces(), 1)
assert.Empty(t, sink1.AllTraces())

assert.Equal(t, defaultSink.AllTraces()[0].SpanCount(), 1)
assert.Equal(t, sink0.AllTraces()[0].SpanCount(), 1)
assert.Equal(t, 1, defaultSink.AllTraces()[0].SpanCount())
assert.Equal(t, 1, sink0.AllTraces()[0].SpanCount())
assert.Equal(t, defaultSink.AllTraces(), sink0.AllTraces())
})
}
Expand Down
6 changes: 3 additions & 3 deletions connector/spanmetricsconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1647,23 +1647,23 @@ func assertDataPointsHaveExactlyOneExemplarForTrace(t *testing.T, metrics pmetri
assert.Greater(t, dps.Len(), 0)
for dpi := 0; dpi < dps.Len(); dpi++ {
dp := dps.At(dpi)
assert.Equal(t, dp.Exemplars().Len(), 1)
assert.Equal(t, 1, dp.Exemplars().Len())
assert.Equal(t, dp.Exemplars().At(0).TraceID(), traceID)
}
case pmetric.MetricTypeHistogram:
dps := metric.Histogram().DataPoints()
assert.Greater(t, dps.Len(), 0)
for dpi := 0; dpi < dps.Len(); dpi++ {
dp := dps.At(dpi)
assert.Equal(t, dp.Exemplars().Len(), 1)
assert.Equal(t, 1, dp.Exemplars().Len())
assert.Equal(t, dp.Exemplars().At(0).TraceID(), traceID)
}
case pmetric.MetricTypeExponentialHistogram:
dps := metric.ExponentialHistogram().DataPoints()
assert.Greater(t, dps.Len(), 0)
for dpi := 0; dpi < dps.Len(); dpi++ {
dp := dps.At(dpi)
assert.Equal(t, dp.Exemplars().Len(), 1)
assert.Equal(t, 1, dp.Exemplars().Len())
assert.Equal(t, dp.Exemplars().At(0).TraceID(), traceID)
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestCache_Get(t *testing.T) {
t.Parallel()
c := tt.lruCache()
gotValue, gotOk := c.Get(tt.key)
if !assert.Equal(t, gotValue, tt.wantValue) {
if !assert.Equal(t, tt.wantValue, gotValue) {
t.Errorf("Get() gotValue = %v, want %v", gotValue, tt.wantValue)
}
if gotOk != tt.wantOk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ func TestMetricDataToLogService(t *testing.T) {
}

func TestMetricCornerCases(t *testing.T) {
assert.Equal(t, min(1, 2), 1)
assert.Equal(t, min(2, 1), 1)
assert.Equal(t, min(1, 1), 1)
assert.Equal(t, 1, min(1, 2))
assert.Equal(t, 1, min(2, 1))
assert.Equal(t, 1, min(1, 1))
var label KeyValues
label.Append("a", "b")
assert.Equal(t, label.String(), "a#$#b")
assert.Equal(t, "a#$#b", label.String())
}

func TestMetricLabelSanitize(t *testing.T) {
Expand All @@ -144,7 +144,7 @@ func TestMetricLabelSanitize(t *testing.T) {
label.Append("0test", "key_0test")
label.Append("test_normal", "test_normal")
label.Append("0test", "key_0test")
assert.Equal(t, label.String(), "key_test#$#key_test|key_0test#$#key_0test|test_normal#$#test_normal|key_0test#$#key_0test")
assert.Equal(t, "key_test#$#key_test|key_0test#$#key_0test|test_normal#$#test_normal|key_0test#$#key_0test", label.String())
label.Sort()
assert.Equal(t, label.String(), "key_0test#$#key_0test|key_0test#$#key_0test|key_test#$#key_test|test_normal#$#test_normal")
assert.Equal(t, "key_0test#$#key_0test|key_0test#$#key_0test|key_test#$#key_test|test_normal#$#test_normal", label.String())
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ func newSegmentID() pcommon.SpanID {
}

func TestSpanKindToShortString(t *testing.T) {
assert.Equal(t, spanKindToShortString(ptrace.SpanKindConsumer), "consumer")
assert.Equal(t, spanKindToShortString(ptrace.SpanKindProducer), "producer")
assert.Equal(t, spanKindToShortString(ptrace.SpanKindClient), "client")
assert.Equal(t, spanKindToShortString(ptrace.SpanKindServer), "server")
assert.Equal(t, spanKindToShortString(ptrace.SpanKindInternal), "internal")
assert.Equal(t, spanKindToShortString(ptrace.SpanKindUnspecified), "")
assert.Equal(t, "consumer", spanKindToShortString(ptrace.SpanKindConsumer))
assert.Equal(t, "producer", spanKindToShortString(ptrace.SpanKindProducer))
assert.Equal(t, "client", spanKindToShortString(ptrace.SpanKindClient))
assert.Equal(t, "server", spanKindToShortString(ptrace.SpanKindServer))
assert.Equal(t, "internal", spanKindToShortString(ptrace.SpanKindInternal))
assert.Equal(t, "", spanKindToShortString(ptrace.SpanKindUnspecified))
}

func TestStatusCodeToShortString(t *testing.T) {
assert.Equal(t, statusCodeToShortString(ptrace.StatusCodeOk), "OK")
assert.Equal(t, statusCodeToShortString(ptrace.StatusCodeError), "ERROR")
assert.Equal(t, statusCodeToShortString(ptrace.StatusCodeUnset), "UNSET")
assert.Equal(t, "OK", statusCodeToShortString(ptrace.StatusCodeOk))
assert.Equal(t, "ERROR", statusCodeToShortString(ptrace.StatusCodeError))
assert.Equal(t, "UNSET", statusCodeToShortString(ptrace.StatusCodeUnset))
}
4 changes: 2 additions & 2 deletions exporter/awsemfexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestNoDimensionRollupFeatureGate(t *testing.T) {
require.NoError(t, err)
cfg := createDefaultConfig()

assert.Equal(t, cfg.(*Config).DimensionRollupOption, "NoDimensionRollup")
assert.Equal(t, "NoDimensionRollup", cfg.(*Config).DimensionRollupOption)
_ = featuregate.GlobalRegistry().Set("awsemf.nodimrollupdefault", false)
}

Expand Down Expand Up @@ -320,7 +320,7 @@ func TestIsApplicationSignalsEnabled(t *testing.T) {
cfg.LogGroupName = tc.logGroupName
}

assert.Equal(t, cfg.isAppSignalsEnabled(), tc.expectedResult)
assert.Equal(t, tc.expectedResult, cfg.isAppSignalsEnabled())
})
}
}
4 changes: 2 additions & 2 deletions exporter/awsemfexporter/emf_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func TestNewExporterWithoutConfig(t *testing.T) {
exp, err := newEmfExporter(expCfg, settings)
assert.Error(t, err)
assert.Nil(t, exp)
assert.Equal(t, settings.Logger, expCfg.logger)
assert.Equal(t, expCfg.logger, settings.Logger)
}

func TestNewExporterWithMetricDeclarations(t *testing.T) {
Expand Down Expand Up @@ -421,5 +421,5 @@ func TestNewEmfExporterWithoutConfig(t *testing.T) {
exp, err := newEmfExporter(expCfg, settings)
assert.Error(t, err)
assert.Nil(t, exp)
assert.Equal(t, settings.Logger, expCfg.logger)
assert.Equal(t, expCfg.logger, settings.Logger)
}
4 changes: 2 additions & 2 deletions exporter/awskinesisexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestCreatingExporter(t *testing.T) {
}),
validateNew: func(tb testing.TB) func(conf aws.Config, opts ...func(*kinesis.Options)) *kinesis.Client {
return func(conf aws.Config, opts ...func(*kinesis.Options)) *kinesis.Client {
assert.Equal(tb, conf.Region, "us-west-2", "Must match the expected region")
assert.Equal(tb, "us-west-2", conf.Region, "Must match the expected region")
k := kinesis.NewFromConfig(conf, opts...)
return k
}
Expand All @@ -50,7 +50,7 @@ func TestCreatingExporter(t *testing.T) {
}),
validateNew: func(tb testing.TB) func(conf aws.Config, opts ...func(*kinesis.Options)) *kinesis.Client {
return func(conf aws.Config, opts ...func(*kinesis.Options)) *kinesis.Client {
assert.Equal(tb, conf.Region, "us-east-1", "Must match the expected region")
assert.Equal(tb, "us-east-1", conf.Region, "Must match the expected region")
k := kinesis.NewFromConfig(conf, opts...)
return k
}
Expand Down
Loading

0 comments on commit 145145c

Please sign in to comment.