Skip to content

Commit

Permalink
[chore]: enable float-compare 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 12, 2024
1 parent 8d7e04d commit 26bcf60
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 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:
- float-compare
- formatter
- go-require
- require-error
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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,require-error,suite-subtest-run,useless-assert
TESTIFYLINT_OPT?= --enable-all --disable=formatter,go-require,require-error,suite-subtest-run,useless-assert

# BUILD_TYPE should be one of (dev, release).
BUILD_TYPE?=release
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/containerinsight/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func checkMetricsAreExpected(t *testing.T, md pmetric.Metrics, fields map[string
dp := dps.At(0)
switch dp.ValueType() {
case pmetric.NumberDataPointValueTypeDouble:
assert.Equal(t, convertToFloat64(fields[metricName]), dp.DoubleValue())
assert.InDelta(t, convertToFloat64(fields[metricName]), dp.DoubleValue(), 0.01)
case pmetric.NumberDataPointValueTypeInt:
assert.Equal(t, convertToInt64(fields[metricName]), dp.IntValue())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ func TestPodStore_decorateCpu(t *testing.T) {

assert.Equal(t, uint64(10), metric.GetField("pod_cpu_request").(uint64))
assert.Equal(t, uint64(10), metric.GetField("pod_cpu_limit").(uint64))
assert.Equal(t, float64(0.25), metric.GetField("pod_cpu_reserved_capacity").(float64))
assert.Equal(t, float64(10), metric.GetField("pod_cpu_utilization_over_pod_limit").(float64))
assert.Equal(t, float64(1), metric.GetField("pod_cpu_usage_total").(float64))
assert.InDelta(t, float64(0.25), metric.GetField("pod_cpu_reserved_capacity").(float64), 0.01)
assert.InDelta(t, float64(10), metric.GetField("pod_cpu_utilization_over_pod_limit").(float64), 0.01)
assert.InDelta(t, float64(1), metric.GetField("pod_cpu_usage_total").(float64), 0.01)

// test container metrics
tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.ContainerNamekey: "ubuntu"}
Expand All @@ -232,7 +232,7 @@ func TestPodStore_decorateCpu(t *testing.T) {

assert.Equal(t, uint64(10), metric.GetField("container_cpu_request").(uint64))
assert.Equal(t, uint64(10), metric.GetField("container_cpu_limit").(uint64))
assert.Equal(t, float64(1), metric.GetField("container_cpu_usage_total").(float64))
assert.InDelta(t, float64(1), metric.GetField("container_cpu_usage_total").(float64), 0.01)
}

func TestPodStore_decorateMem(t *testing.T) {
Expand All @@ -248,8 +248,8 @@ func TestPodStore_decorateMem(t *testing.T) {

assert.Equal(t, uint64(52428800), metric.GetField("pod_memory_request").(uint64))
assert.Equal(t, uint64(52428800), metric.GetField("pod_memory_limit").(uint64))
assert.Equal(t, float64(12.5), metric.GetField("pod_memory_reserved_capacity").(float64))
assert.Equal(t, float64(20), metric.GetField("pod_memory_utilization_over_pod_limit").(float64))
assert.InDelta(t, float64(12.5), metric.GetField("pod_memory_reserved_capacity").(float64), 0.01)
assert.InDelta(t, float64(20), metric.GetField("pod_memory_utilization_over_pod_limit").(float64), 0.01)
assert.Equal(t, uint64(10*1024*1024), metric.GetField("pod_memory_working_set").(uint64))

tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.ContainerNamekey: "ubuntu"}
Expand All @@ -260,7 +260,7 @@ func TestPodStore_decorateMem(t *testing.T) {

assert.Equal(t, uint64(52428800), metric.GetField("container_memory_request").(uint64))
assert.Equal(t, uint64(52428800), metric.GetField("container_memory_limit").(uint64))
assert.Equal(t, float64(10*1024*1024), metric.GetField("container_memory_working_set").(float64))
assert.InDelta(t, float64(10*1024*1024), metric.GetField("container_memory_working_set").(float64), 0.01)
}

func TestPodStore_addContainerCount(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func TestSampleLoad(t *testing.T) {
samplerInstance.sampleLoad()
}

assert.Equal(t, calcExpectedLoad(counterReturnValues, loadAvgFactor1m), samplerInstance.loadAvg1m)
assert.Equal(t, calcExpectedLoad(counterReturnValues, loadAvgFactor5m), samplerInstance.loadAvg5m)
assert.Equal(t, calcExpectedLoad(counterReturnValues, loadAvgFactor15m), samplerInstance.loadAvg15m)
assert.InDelta(t, calcExpectedLoad(counterReturnValues, loadAvgFactor1m), samplerInstance.loadAvg1m, 0.01)
assert.InDelta(t, calcExpectedLoad(counterReturnValues, loadAvgFactor5m), samplerInstance.loadAvg5m, 0.01)
assert.InDelta(t, calcExpectedLoad(counterReturnValues, loadAvgFactor15m), samplerInstance.loadAvg15m, 0.01)
}

func calcExpectedLoad(scrapedValues []int64, loadAvgFactor float64) float64 {
Expand Down
6 changes: 3 additions & 3 deletions receiver/prometheusreceiver/metrics_receiver_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func isFirstFailedScrape(metrics []pmetric.Metric, normalizedNames bool) bool {
func assertUp(t *testing.T, expected float64, metrics []pmetric.Metric) {
for _, m := range metrics {
if m.Name() == "up" {
assert.Equal(t, expected, m.Gauge().DataPoints().At(0).DoubleValue()) // (assumed up will not have multiple datapoints)
assert.InDelta(t, expected, m.Gauge().DataPoints().At(0).DoubleValue(), 0.01) // (assumed up will not have multiple datapoints)
return
}
}
Expand Down Expand Up @@ -620,7 +620,7 @@ func compareSummaryStartTimestamp(timeStamp pcommon.Timestamp) summaryPointCompa

func compareDoubleValue(doubleVal float64) numberPointComparator {
return func(t *testing.T, numberDataPoint pmetric.NumberDataPoint) {
assert.Equal(t, doubleVal, numberDataPoint.DoubleValue(), "Metric double value does not match")
assert.InDelta(t, doubleVal, numberDataPoint.DoubleValue(), 0.01, "Metric double value does not match")
}
}

Expand All @@ -634,7 +634,7 @@ func assertNormalNan() numberPointComparator {
func compareHistogram(count uint64, sum float64, upperBounds []float64, buckets []uint64) histogramPointComparator {
return func(t *testing.T, histogramDataPoint pmetric.HistogramDataPoint) {
assert.Equal(t, count, histogramDataPoint.Count(), "Histogram count value does not match")
assert.Equal(t, sum, histogramDataPoint.Sum(), "Histogram sum value does not match")
assert.InDelta(t, sum, histogramDataPoint.Sum(), 0.01, "Histogram sum value does not match")
assert.Equal(t, upperBounds, histogramDataPoint.ExplicitBounds().AsRaw(), "Histogram upper bounds values do not match")
assert.Equal(t, buckets, histogramDataPoint.BucketCounts().AsRaw(), "Histogram bucket count values do not match")
}
Expand Down
8 changes: 4 additions & 4 deletions receiver/redisreceiver/latencystats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
func TestParseLatencyStats(t *testing.T) {
ls, err := parseLatencyStats("p50=181.247,p55=182.271,p99=309.247,p99.9=1023.999")
require.NoError(t, err)
require.Equal(t, 181.247, ls["p50"])
require.Equal(t, 182.271, ls["p55"])
require.Equal(t, 309.247, ls["p99"])
require.Equal(t, 1023.999, ls["p99.9"])
require.InDelta(t, 181.247, ls["p50"], 0.01)
require.InDelta(t, 182.271, ls["p55"], 0.01)
require.InDelta(t, 309.247, ls["p99"], 0.01)
require.InDelta(t, 1023.999, ls["p99.9"], 0.01)
}

func TestParseMalformedLatencyStats(t *testing.T) {
Expand Down

0 comments on commit 26bcf60

Please sign in to comment.