Skip to content

Commit

Permalink
[chore]: enable negative-positive rule from testifylint
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 committed Sep 6, 2024
1 parent 0e2bea5 commit 142b28a
Show file tree
Hide file tree
Showing 23 changed files with 39 additions and 40 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ linters-settings:
- float-compare
- formatter
- go-require
- negative-positive
- require-error
- suite-dont-use-pkg
- suite-subtest-run
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=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,require-error,suite-dont-use-pkg,suite-subtest-run,useless-assert

# BUILD_TYPE should be one of (dev, release).
BUILD_TYPE?=release
Expand Down
8 changes: 4 additions & 4 deletions connector/spanmetricsconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func verifyExemplarsExist(t testing.TB, input pmetric.Metrics) bool {
dps := metric.Histogram().DataPoints()
for dp := 0; dp < dps.Len(); dp++ {
d := dps.At(dp)
assert.Greater(t, d.Exemplars().Len(), 0)
assert.Positive(t, d.Exemplars().Len())
}
}
}
Expand Down Expand Up @@ -1645,23 +1645,23 @@ func assertDataPointsHaveExactlyOneExemplarForTrace(t *testing.T, metrics pmetri
switch metric.Type() {
case pmetric.MetricTypeSum:
dps := metric.Sum().DataPoints()
assert.Greater(t, dps.Len(), 0)
assert.Positive(t, dps.Len())
for dpi := 0; dpi < dps.Len(); dpi++ {
dp := dps.At(dpi)
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)
assert.Positive(t, dps.Len())
for dpi := 0; dpi < dps.Len(); dpi++ {
dp := dps.At(dpi)
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)
assert.Positive(t, dps.Len())
for dpi := 0; dpi < dps.Len(); dpi++ {
dp := dps.At(dpi)
assert.Equal(t, 1, dp.Exemplars().Len())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestDoWithRetries(t *testing.T) {
)
retryNum, err = retrier.DoWithRetries(ctx, func(context.Context) error { return errors.New("action failed") })
require.Error(t, err)
assert.Greater(t, retryNum, int64(0))
assert.Positive(t, retryNum)
}

func TestNoRetriesOnPermanentError(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions exporter/loadbalancingexporter/log_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ func TestRollingUpdatesWhenConsumeLogs(t *testing.T) {
mu.Lock()
require.Equal(t, []string{"127.0.0.2"}, lastResolved)
mu.Unlock()
require.Greater(t, counter1.Load(), int64(0))
require.Greater(t, counter2.Load(), int64(0))
require.Positive(t, counter1.Load())
require.Positive(t, counter2.Load())
}

func randomLogs() plog.Logs {
Expand Down
4 changes: 2 additions & 2 deletions exporter/loadbalancingexporter/metrics_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,8 @@ func TestRollingUpdatesWhenConsumeMetrics(t *testing.T) {
mu.Lock()
require.Equal(t, []string{"127.0.0.2"}, lastResolved)
mu.Unlock()
require.Greater(t, counter1.Load(), int64(0))
require.Greater(t, counter2.Load(), int64(0))
require.Positive(t, counter1.Load())
require.Positive(t, counter2.Load())
}

func randomMetrics(t require.TestingT, rmCount int, smCount int, mCount int, dpCount int) pmetric.Metrics {
Expand Down
4 changes: 2 additions & 2 deletions exporter/loadbalancingexporter/trace_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ func TestRollingUpdatesWhenConsumeTraces(t *testing.T) {
mu.Lock()
require.Equal(t, []string{"127.0.0.2"}, lastResolved)
mu.Unlock()
require.Greater(t, counter1.Load(), int64(0))
require.Greater(t, counter2.Load(), int64(0))
require.Positive(t, counter1.Load())
require.Positive(t, counter2.Load())
}

func benchConsumeTraces(b *testing.B, endpointsCount int, tracesCount int) {
Expand Down
2 changes: 1 addition & 1 deletion exporter/mezmoexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestAddsRequiredAttributes(t *testing.T) {

lines := body.Lines
for _, line := range lines {
assert.Greater(t, line.Timestamp, int64(0))
assert.Positive(t, line.Timestamp)
assert.Equal(t, "info", line.Level)
assert.Equal(t, "", line.App)
assert.Equal(t, "minimal attribute log", line.Line)
Expand Down
4 changes: 2 additions & 2 deletions exporter/splunkhecexporter/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func Test_Heartbeat_success(t *testing.T) {
require.NoError(t, err)
return len(got) != 0
}, time.Second, 10*time.Millisecond)
assert.Greater(t, got[0], int64(0), "there should be at least one success metric datapoint")
assert.Positive(t, got[0], "there should be at least one success metric datapoint")
attrs, err := getAttributes(reader, sentMetricsName)
require.NoError(t, err)
assert.Equal(t, attribute.NewSet(attribute.String(metricLabelKey, metricLabelVal)), attrs[0])
Expand All @@ -161,7 +161,7 @@ func Test_Heartbeat_failure(t *testing.T) {
require.NoError(t, err)
return len(got) != 0
}, time.Second, 10*time.Millisecond)
assert.Greater(t, got[0], int64(0), "there should be at least one failure metric datapoint")
assert.Positive(t, got[0], "there should be at least one failure metric datapoint")
attrs, err := getAttributes(reader, defaultHBFailedMetricsName)
require.NoError(t, err)
assert.Equal(t, attribute.NewSet(attribute.String(metricLabelKey, metricLabelVal)), attrs[0])
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/cwlogs/pusher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestValidateLogEventWithMutating(t *testing.T) {
logEvent.GeneratedTime = time.Now()
err := logEvent.Validate(zap.NewNop())
assert.NoError(t, err)
assert.Greater(t, *logEvent.InputLogEvent.Timestamp, int64(0))
assert.Positive(t, *logEvent.InputLogEvent.Timestamp)
assert.Len(t, *logEvent.InputLogEvent.Message, 64-perEventHeaderBytes)

maxEventPayloadBytes = defaultMaxEventPayloadBytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestGenerateResource(t *testing.T) {
if rscID == ResourceEmpty {
assert.Equal(t, 0, rsc.Attributes().Len())
} else {
assert.Greater(t, rsc.Attributes().Len(), 0)
assert.Positive(t, rsc.Attributes().Len())
}
}
}
8 changes: 4 additions & 4 deletions internal/otelarrow/test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,13 @@ func failureMemoryLimitEnding(t *testing.T, _ testParams, testCon *testConsumer,
rSigs, rMsgs := logSigs(testCon.recvLogs)

// Test for arrow receiver stream errors on both sides.
require.Less(t, 0, eSigs["arrow stream error|||code///message///where"], "should have exporter arrow stream errors: %v", eMsgs)
require.Less(t, 0, rSigs["arrow stream error|||code///message///where"], "should have receiver arrow stream errors: %v", rSigs)
require.Positive(t, eSigs["arrow stream error|||code///message///where"], "should have exporter arrow stream errors: %v", eMsgs)
require.Positive(t, rSigs["arrow stream error|||code///message///where"], "should have receiver arrow stream errors: %v", rSigs)

// Ensure both side's error logs include memory limit errors
// one way or another.
require.Less(t, 0, countMemoryLimitErrors(rMsgs), "should have memory limit errors: %v", rMsgs)
require.Less(t, 0, countMemoryLimitErrors(eMsgs), "should have memory limit errors: %v", eMsgs)
require.Positive(t, countMemoryLimitErrors(rMsgs), "should have memory limit errors: %v", rMsgs)
require.Positive(t, countMemoryLimitErrors(eMsgs), "should have memory limit errors: %v", eMsgs)

return nil, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/stanza/fileconsumer/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestReadUsingNopEncoding(t *testing.T) {
// Create a file, then start
temp := filetest.OpenTemp(t, tempDir)
bytesWritten, err := temp.Write(tc.input)
require.Greater(t, bytesWritten, 0)
require.Positive(t, bytesWritten)
require.NoError(t, err)
require.NoError(t, operator.Start(testutil.NewUnscopedMockPersister()))
defer func() {
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestNopEncodingDifferentLogSizes(t *testing.T) {
// Create a file, then start
temp := filetest.OpenTemp(t, tempDir)
bytesWritten, err := temp.Write(tc.input)
require.Greater(t, bytesWritten, 0)
require.Positive(t, bytesWritten)
require.NoError(t, err)
require.NoError(t, operator.Start(testutil.NewUnscopedMockPersister()))
defer func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/input/file/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestReadUsingNopEncoding(t *testing.T) {
// Create a file, then start
temp := openTemp(t, tempDir)
bytesWritten, err := temp.Write(tc.input)
require.Greater(t, bytesWritten, 0)
require.Positive(t, bytesWritten)
require.NoError(t, err)
require.NoError(t, operator.Start(testutil.NewUnscopedMockPersister()))
defer func() {
Expand Down
10 changes: 5 additions & 5 deletions processor/k8sattributesprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func TestIPDetectionFromContext(t *testing.T) {
m.assertBatchesLen(1)
m.assertResourceObjectLen(0)
m.assertResource(0, func(r pcommon.Resource) {
require.Greater(t, r.Attributes().Len(), 0)
require.Positive(t, r.Attributes().Len())
assertResourceHasStringAttribute(t, r, "k8s.pod.ip", "1.1.1.1")
})
}
Expand Down Expand Up @@ -537,7 +537,7 @@ func TestIPSourceWithoutPodAssociation(t *testing.T) {
m.testConsume(ctx, traces, metrics, logs, nil)
m.assertBatchesLen(i + 1)
m.assertResource(i, func(res pcommon.Resource) {
require.Greater(t, res.Attributes().Len(), 0)
require.Positive(t, res.Attributes().Len())
assertResourceHasStringAttribute(t, res, "k8s.pod.ip", tc.out)
})
})
Expand Down Expand Up @@ -623,7 +623,7 @@ func TestIPSourceWithPodAssociation(t *testing.T) {
m.testConsume(ctx, traces, metrics, logs, nil)
m.assertBatchesLen(i + 1)
m.assertResource(i, func(res pcommon.Resource) {
require.Greater(t, res.Attributes().Len(), 0)
require.Positive(t, res.Attributes().Len())
assertResourceHasStringAttribute(t, res, tc.outLabel, tc.outValue)
})
})
Expand Down Expand Up @@ -666,7 +666,7 @@ func TestPodUID(t *testing.T) {
m.assertBatchesLen(1)
m.assertResourceObjectLen(0)
m.assertResource(0, func(r pcommon.Resource) {
require.Greater(t, r.Attributes().Len(), 0)
require.Positive(t, r.Attributes().Len())
assertResourceHasStringAttribute(t, r, "k8s.pod.uid", "ef10d10b-2da5-4030-812e-5f45c1531227")
})
}
Expand Down Expand Up @@ -728,7 +728,7 @@ func TestAddPodLabels(t *testing.T) {
m.assertBatchesLen(i + 1)
m.assertResourceObjectLen(i)
m.assertResource(i, func(res pcommon.Resource) {
require.Greater(t, res.Attributes().Len(), 0)
require.Positive(t, res.Attributes().Len())
assertResourceHasStringAttribute(t, res, "k8s.pod.ip", ip)
for k, v := range attrs {
assertResourceHasStringAttribute(t, res, k, v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import (

func TestTimeProvider(t *testing.T) {
clock := MonotonicClock{}
assert.Greater(t, clock.getCurSecond(), int64(0))
assert.Positive(t, clock.getCurSecond())
}
2 changes: 1 addition & 1 deletion receiver/couchdbreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestScrape(t *testing.T) {

var partialScrapeErr scrapererror.PartialScrapeError
require.ErrorAs(t, err, &partialScrapeErr, "returned error was not PartialScrapeError")
require.Greater(t, partialScrapeErr.Failed, 0, "Expected scrape failures, but none were recorded!")
require.Positive(t, partialScrapeErr.Failed, "Expected scrape failures, but none were recorded!")
})

t.Run("scrape error: failed to connect to client", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion receiver/fluentforwardreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func TestUnixEndpoint(t *testing.T) {

n, err := conn.Write(parseHexDump("testdata/message-event"))
require.NoError(t, err)
require.Greater(t, n, 0)
require.Positive(t, n)

var converted []plog.Logs
require.Eventually(t, func() bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestScrape_Errors(t *testing.T) {
pageSize = test.pageSize
} else {
pageSize = getPageSize()
assert.Greater(t, pageSize, uint64(0))
assert.Positive(t, pageSize)
assert.Zero(t, pageSize%4096) // page size on Windows should always be a multiple of 4KB
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func TestScrape(t *testing.T) {
var scraperErr scrapererror.PartialScrapeError
require.ErrorAs(t, err, &scraperErr)
noProcessesErrored := scraperErr.Failed
require.Lessf(t, 0, noProcessesErrored, "Failed to scrape metrics - : error, but 0 failed process %v", err)
require.Lessf(t, 0, noProcessesScraped, "Failed to scrape metrics - : 0 successful scrapes %v", err)
require.Positivef(t, noProcessesErrored, "Failed to scrape metrics - : error, but 0 failed process %v", err)
require.Positivef(t, noProcessesScraped, "Failed to scrape metrics - : 0 successful scrapes %v", err)
}

require.Greater(t, md.ResourceMetrics().Len(), 1)
Expand Down
4 changes: 2 additions & 2 deletions receiver/influxdbreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestWriteLineProtocol_v2API(t *testing.T) {
require.NoError(t, err)

metrics := nextConsumer.lastMetricsConsumed
if assert.NotNil(t, metrics) && assert.Less(t, 0, metrics.DataPointCount()) {
if assert.NotNil(t, metrics) && assert.Positive(t, metrics.DataPointCount()) {
assert.Equal(t, 1, metrics.MetricCount())
metric := metrics.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0)
assert.Equal(t, "cpu_temp", metric.Name())
Expand All @@ -77,7 +77,7 @@ func TestWriteLineProtocol_v2API(t *testing.T) {
require.NoError(t, err)

metrics := nextConsumer.lastMetricsConsumed
if assert.NotNil(t, metrics) && assert.Less(t, 0, metrics.DataPointCount()) {
if assert.NotNil(t, metrics) && assert.Positive(t, metrics.DataPointCount()) {
assert.Equal(t, 1, metrics.MetricCount())
metric := metrics.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0)
assert.Equal(t, "cpu_temp", metric.Name())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestUnstructuredListToLogData(t *testing.T) {
logRecords := rl.ScopeLogs().At(0).LogRecords()
assert.Equal(t, 1, rl.ScopeLogs().Len())
assert.Equal(t, 1, logRecords.Len())
assert.Greater(t, logRecords.At(0).ObservedTimestamp().AsTime().Unix(), int64(0))
assert.Positive(t, logRecords.At(0).ObservedTimestamp().AsTime().Unix())
assert.Equal(t, logRecords.At(0).ObservedTimestamp().AsTime().Unix(), observedAt.Unix())
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ service:
}
}

require.Greater(t, totalSamples, 0, "Expected at least 1 sample")
require.Positive(t, totalSamples, "Expected at least 1 sample")
// On every alternative scrape the prior scrape will be reported as sale.
// Expect at least:
// * The first scrape will NOT return stale markers
Expand Down

0 comments on commit 142b28a

Please sign in to comment.