Skip to content

Commit

Permalink
[chore]: enable compares and empty rules from testifylint (#34976)
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
[compares](https://github.com/Antonboom/testifylint?tab=readme-ov-file#compares)
and
[empty](https://github.com/Antonboom/testifylint?tab=readme-ov-file#empty)
rules from [testifylint](https://github.com/Antonboom/testifylint)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 authored Sep 3, 2024
1 parent a77faff commit 1ec7cfe
Show file tree
Hide file tree
Showing 102 changed files with 275 additions and 277 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ linters-settings:

testifylint:
disable:
- compares
- empty
- error-is-as
- expected-actual
- float-compare
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=compares,empty,error-is-as,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=error-is-as,expected-actual,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
6 changes: 3 additions & 3 deletions cmd/telemetrygen/internal/logs/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func TestRateOfLogs(t *testing.T) {

// verify
// the minimum acceptable number of logs for the rate of 10/sec for half a second
assert.True(t, len(m.logs) >= 5, "there should have been 5 or more logs, had %d", len(m.logs))
assert.GreaterOrEqual(t, len(m.logs), 5, "there should have been 5 or more logs, had %d", len(m.logs))
// the maximum acceptable number of logs for the rate of 10/sec for half a second
assert.True(t, len(m.logs) <= 20, "there should have been less than 20 logs, had %d", len(m.logs))
assert.LessOrEqual(t, len(m.logs), 20, "there should have been less than 20 logs, had %d", len(m.logs))
}

func TestUnthrottled(t *testing.T) {
Expand All @@ -109,7 +109,7 @@ func TestUnthrottled(t *testing.T) {
logger, _ := zap.NewDevelopment()
require.NoError(t, Run(cfg, expFunc, logger))

assert.True(t, len(m.logs) > 100, "there should have been more than 100 logs, had %d", len(m.logs))
assert.Greater(t, len(m.logs), 100, "there should have been more than 100 logs, had %d", len(m.logs))
}

func TestCustomBody(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/telemetrygen/internal/metrics/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func TestRateOfMetrics(t *testing.T) {

// assert
// the minimum acceptable number of metrics for the rate of 10/sec for half a second
assert.True(t, len(m.rms) >= 6, "there should have been more than 6 metrics, had %d", len(m.rms))
assert.GreaterOrEqual(t, len(m.rms), 6, "there should have been more than 6 metrics, had %d", len(m.rms))
// the maximum acceptable number of metrics for the rate of 10/sec for half a second
assert.True(t, len(m.rms) <= 20, "there should have been less than 20 metrics, had %d", len(m.rms))
assert.LessOrEqual(t, len(m.rms), 20, "there should have been less than 20 metrics, had %d", len(m.rms))
}

func TestUnthrottled(t *testing.T) {
Expand All @@ -117,7 +117,7 @@ func TestUnthrottled(t *testing.T) {
require.NoError(t, Run(cfg, expFunc, logger))

// assert
assert.True(t, len(m.rms) > 100, "there should have been more than 100 metrics, had %d", len(m.rms))
assert.Greater(t, len(m.rms), 100, "there should have been more than 100 metrics, had %d", len(m.rms))
}

func TestSumNoTelemetryAttrs(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions cmd/telemetrygen/internal/traces/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ func TestRateOfSpans(t *testing.T) {
}

// sanity check
require.Len(t, syncer.spans, 0)
require.Empty(t, syncer.spans)

// test
require.NoError(t, Run(cfg, zap.NewNop()))

// verify
// the minimum acceptable number of spans for the rate of 10/sec for half a second
assert.True(t, len(syncer.spans) >= 6, "there should have been more than 6 spans, had %d", len(syncer.spans))
assert.GreaterOrEqual(t, len(syncer.spans), 6, "there should have been more than 6 spans, had %d", len(syncer.spans))
// the maximum acceptable number of spans for the rate of 10/sec for half a second
assert.True(t, len(syncer.spans) <= 20, "there should have been less than 20 spans, had %d", len(syncer.spans))
assert.LessOrEqual(t, len(syncer.spans), 20, "there should have been less than 20 spans, had %d", len(syncer.spans))
}

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

// sanity check
require.Len(t, syncer.spans, 0)
require.Empty(t, syncer.spans)

// test
require.NoError(t, Run(cfg, zap.NewNop()))
Expand Down Expand Up @@ -154,14 +154,14 @@ func TestUnthrottled(t *testing.T) {
}

// sanity check
require.Len(t, syncer.spans, 0)
require.Empty(t, syncer.spans)

// test
require.NoError(t, Run(cfg, zap.NewNop()))

// verify
// the minimum acceptable number of spans -- the real number should be > 10k, but CI env might be slower
assert.True(t, len(syncer.spans) > 100, "there should have been more than 100 spans, had %d", len(syncer.spans))
assert.Greater(t, len(syncer.spans), 100, "there should have been more than 100 spans, had %d", len(syncer.spans))
}

func TestSpanKind(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions connector/exceptionsconnector/connector_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestConnectorConsumeTraces(t *testing.T) {
assert.NoError(t, err)

metrics := msink.AllMetrics()
assert.Greater(t, len(metrics), 0)
assert.NotEmpty(t, metrics)
tc.verifier(t, metrics[len(metrics)-1])
}
})
Expand All @@ -103,7 +103,7 @@ func TestConnectorConsumeTraces(t *testing.T) {
assert.NoError(t, err)

metrics := msink.AllMetrics()
assert.Greater(t, len(metrics), 0)
assert.NotEmpty(t, metrics)
verifyBadMetricsOkay(t, metrics[len(metrics)-1])
})

Expand Down
30 changes: 15 additions & 15 deletions connector/routingconnector/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func TestLogsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {
require.NoError(t, conn.ConsumeLogs(context.Background(), l))

assert.Len(t, defaultSink.AllLogs(), 1)
assert.Len(t, sink0.AllLogs(), 0)
assert.Len(t, sink1.AllLogs(), 0)
assert.Empty(t, sink0.AllLogs())
assert.Empty(t, sink1.AllLogs())
})

t.Run("logs matched one expression", func(t *testing.T) {
Expand All @@ -153,9 +153,9 @@ func TestLogsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {

require.NoError(t, conn.ConsumeLogs(context.Background(), l))

assert.Len(t, defaultSink.AllLogs(), 0)
assert.Empty(t, defaultSink.AllLogs())
assert.Len(t, sink0.AllLogs(), 1)
assert.Len(t, sink1.AllLogs(), 0)
assert.Empty(t, sink1.AllLogs())
})

t.Run("logs matched by two expressions", func(t *testing.T) {
Expand All @@ -173,7 +173,7 @@ func TestLogsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {

require.NoError(t, conn.ConsumeLogs(context.Background(), l))

assert.Len(t, defaultSink.AllLogs(), 0)
assert.Empty(t, defaultSink.AllLogs())
assert.Len(t, sink0.AllLogs(), 1)
assert.Len(t, sink1.AllLogs(), 1)

Expand Down Expand Up @@ -222,7 +222,7 @@ func TestLogsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {

assert.Len(t, defaultSink.AllLogs(), 1)
assert.Len(t, sink0.AllLogs(), 1)
assert.Len(t, sink1.AllLogs(), 0)
assert.Empty(t, sink1.AllLogs())

assert.Equal(t, defaultSink.AllLogs()[0].LogRecordCount(), 1)
assert.Equal(t, sink0.AllLogs()[0].LogRecordCount(), 1)
Expand Down Expand Up @@ -294,8 +294,8 @@ func TestLogsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {
require.NoError(t, conn.ConsumeLogs(context.Background(), l))

assert.Len(t, defaultSink.AllLogs(), 1)
assert.Len(t, sink0.AllLogs(), 0)
assert.Len(t, sink1.AllLogs(), 0)
assert.Empty(t, sink0.AllLogs())
assert.Empty(t, sink1.AllLogs())
})

t.Run("logs matched one expression", func(t *testing.T) {
Expand All @@ -309,9 +309,9 @@ func TestLogsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {

require.NoError(t, conn.ConsumeLogs(context.Background(), l))

assert.Len(t, defaultSink.AllLogs(), 0)
assert.Empty(t, defaultSink.AllLogs())
assert.Len(t, sink0.AllLogs(), 1)
assert.Len(t, sink1.AllLogs(), 0)
assert.Empty(t, sink1.AllLogs())
})

t.Run("logs matched by two expressions, but sinks to one", func(t *testing.T) {
Expand All @@ -329,9 +329,9 @@ func TestLogsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {

require.NoError(t, conn.ConsumeLogs(context.Background(), l))

assert.Len(t, defaultSink.AllLogs(), 0)
assert.Empty(t, defaultSink.AllLogs())
assert.Len(t, sink0.AllLogs(), 1)
assert.Len(t, sink1.AllLogs(), 0)
assert.Empty(t, sink1.AllLogs())

assert.Equal(t, sink0.AllLogs()[0].LogRecordCount(), 2)
})
Expand All @@ -353,7 +353,7 @@ func TestLogsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {

assert.Len(t, defaultSink.AllLogs(), 1)
assert.Len(t, sink0.AllLogs(), 1)
assert.Len(t, sink1.AllLogs(), 0)
assert.Empty(t, sink1.AllLogs())

rlog := defaultSink.AllLogs()[0].ResourceLogs().At(0)
attr, ok := rlog.Resource().Attributes().Get("X-Tenant")
Expand All @@ -374,7 +374,7 @@ func TestLogsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {

assert.Len(t, defaultSink.AllLogs(), 1)
assert.Len(t, sink0.AllLogs(), 1)
assert.Len(t, sink1.AllLogs(), 0)
assert.Empty(t, sink1.AllLogs())

assert.Equal(t, defaultSink.AllLogs()[0].LogRecordCount(), 1)
assert.Equal(t, sink0.AllLogs()[0].LogRecordCount(), 1)
Expand Down Expand Up @@ -433,7 +433,7 @@ func TestLogsResourceAttributeDroppedByOTTL(t *testing.T) {
v, ok := attrs.Get("attr")
assert.True(t, ok, "non routing attributes shouldn't be dropped")
assert.Equal(t, "acme", v.Str())
assert.Len(t, sink0.AllLogs(), 0,
assert.Empty(t, sink0.AllLogs(),
"metrics should not be routed to default pipeline",
)
}
Expand Down
30 changes: 15 additions & 15 deletions connector/routingconnector/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func TestMetricsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {
require.NoError(t, conn.ConsumeMetrics(context.Background(), m))

assert.Len(t, defaultSink.AllMetrics(), 1)
assert.Len(t, sink0.AllMetrics(), 0)
assert.Len(t, sink1.AllMetrics(), 0)
assert.Empty(t, sink0.AllMetrics())
assert.Empty(t, sink1.AllMetrics())
})

t.Run("metric matched by one of two expressions", func(t *testing.T) {
Expand All @@ -158,9 +158,9 @@ func TestMetricsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {

require.NoError(t, conn.ConsumeMetrics(context.Background(), m))

assert.Len(t, defaultSink.AllMetrics(), 0)
assert.Empty(t, defaultSink.AllMetrics())
assert.Len(t, sink0.AllMetrics(), 1)
assert.Len(t, sink1.AllMetrics(), 0)
assert.Empty(t, sink1.AllMetrics())
})

t.Run("metric matched by two expressions", func(t *testing.T) {
Expand All @@ -182,7 +182,7 @@ func TestMetricsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {

require.NoError(t, conn.ConsumeMetrics(context.Background(), m))

assert.Len(t, defaultSink.AllMetrics(), 0)
assert.Empty(t, defaultSink.AllMetrics())
assert.Len(t, sink0.AllMetrics(), 1)
assert.Len(t, sink1.AllMetrics(), 1)

Expand Down Expand Up @@ -237,7 +237,7 @@ func TestMetricsAreCorrectlySplitPerResourceAttributeWithOTTL(t *testing.T) {

assert.Len(t, defaultSink.AllMetrics(), 1)
assert.Len(t, sink0.AllMetrics(), 1)
assert.Len(t, sink1.AllMetrics(), 0)
assert.Empty(t, sink1.AllMetrics())

assert.Equal(t, defaultSink.AllMetrics()[0].MetricCount(), 1)
assert.Equal(t, sink0.AllMetrics()[0].MetricCount(), 1)
Expand Down Expand Up @@ -312,8 +312,8 @@ func TestMetricsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {
require.NoError(t, conn.ConsumeMetrics(context.Background(), m))

assert.Len(t, defaultSink.AllMetrics(), 1)
assert.Len(t, sink0.AllMetrics(), 0)
assert.Len(t, sink1.AllMetrics(), 0)
assert.Empty(t, sink0.AllMetrics())
assert.Empty(t, sink1.AllMetrics())
})

t.Run("metric matched by one of two expressions", func(t *testing.T) {
Expand All @@ -329,9 +329,9 @@ func TestMetricsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {

require.NoError(t, conn.ConsumeMetrics(context.Background(), m))

assert.Len(t, defaultSink.AllMetrics(), 0)
assert.Empty(t, defaultSink.AllMetrics())
assert.Len(t, sink0.AllMetrics(), 1)
assert.Len(t, sink1.AllMetrics(), 0)
assert.Empty(t, sink1.AllMetrics())
})

t.Run("metric matched by two expressions, but sinks to one", func(t *testing.T) {
Expand All @@ -353,9 +353,9 @@ func TestMetricsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {

require.NoError(t, conn.ConsumeMetrics(context.Background(), m))

assert.Len(t, defaultSink.AllMetrics(), 0)
assert.Empty(t, defaultSink.AllMetrics())
assert.Len(t, sink0.AllMetrics(), 1)
assert.Len(t, sink1.AllMetrics(), 0)
assert.Empty(t, sink1.AllMetrics())

assert.Equal(t, sink0.AllMetrics()[0].MetricCount(), 2)
})
Expand All @@ -381,7 +381,7 @@ func TestMetricsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {

assert.Len(t, defaultSink.AllMetrics(), 1)
assert.Len(t, sink0.AllMetrics(), 1)
assert.Len(t, sink1.AllMetrics(), 0)
assert.Empty(t, sink1.AllMetrics())

rmetric := defaultSink.AllMetrics()[0].ResourceMetrics().At(0)
attr, ok := rmetric.Resource().Attributes().Get("value")
Expand All @@ -404,7 +404,7 @@ func TestMetricsAreCorrectlyMatchOnceWithOTTL(t *testing.T) {

assert.Len(t, defaultSink.AllMetrics(), 1)
assert.Len(t, sink0.AllMetrics(), 1)
assert.Len(t, sink1.AllMetrics(), 0)
assert.Empty(t, sink1.AllMetrics())

assert.Equal(t, defaultSink.AllMetrics()[0].MetricCount(), 1)
assert.Equal(t, sink0.AllMetrics()[0].MetricCount(), 1)
Expand Down Expand Up @@ -463,7 +463,7 @@ func TestMetricsResourceAttributeDroppedByOTTL(t *testing.T) {
v, ok := attrs.Get("attr")
assert.True(t, ok, "non routing attributes shouldn't be dropped")
assert.Equal(t, "acme", v.Str())
require.Len(t, sink0.AllMetrics(), 0,
require.Empty(t, sink0.AllMetrics(),
"metrics should not be routed to default pipeline",
)
}
Expand Down
Loading

0 comments on commit 1ec7cfe

Please sign in to comment.