Skip to content

Commit

Permalink
testifylint: enable float-compare
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Sep 15, 2024
1 parent 0824fc2 commit 57d95f3
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 58 deletions.
13 changes: 1 addition & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,8 @@ linters-settings:
disabled: true
testifylint:
disable:
- float-compare
- go-require
enable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- len
- require-error
- suite-dont-use-pkg
- suite-extra-assert-call
enable-all: true

run:
go: "1.22"
Expand Down
2 changes: 1 addition & 1 deletion cmd/all-in-one/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func getSamplingStrategy(t *testing.T) {
require.NoError(t, jsonpb.Unmarshal(bytes.NewReader(body), &queryResponse))

assert.NotNil(t, queryResponse.ProbabilisticSampling)
assert.EqualValues(t, 1.0, queryResponse.ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 1.0, queryResponse.ProbabilisticSampling.SamplingRate, 0.01)
}

func getServicesAPIV3(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestStartGRPC(t *testing.T) {
c := api_v2.NewSamplingManagerClient(conn)
response, err := c.GetSamplingStrategy(context.Background(), &api_v2.SamplingStrategyParameters{ServiceName: "foo"})
require.NoError(t, err)
require.Equal(t, 0.8, response.ProbabilisticSampling.SamplingRate)
require.InDelta(t, 0.8, response.ProbabilisticSampling.SamplingRate, 0.01)

require.NoError(t, ext.Shutdown(context.Background()))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/handler_deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func TestGetDependenciesSuccess(t *testing.T) {
actual := data.(map[string]any)
assert.Equal(t, "killer", actual["parent"])
assert.Equal(t, "queen", actual["child"])
assert.Equal(t, 12.00, actual["callCount"]) // recovered type is float
assert.InDelta(t, 12.00, actual["callCount"], 0.01) // recovered type is float
require.NoError(t, err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ func TestGetMinStep(t *testing.T) {

// Verify
require.NoError(t, err)
assert.Equal(t, float64(5), response.Data)
assert.InDelta(t, float64(5), response.Data, 0.01)
}

// getJSON fetches a JSON document from a server via HTTP GET
Expand Down
4 changes: 2 additions & 2 deletions crossdock/services/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestGetSamplingRateInternal(t *testing.T) {
if test.shouldErr {
require.EqualError(t, err, errSamplingRateMissing.Error())
}
assert.EqualValues(t, test.rate, rate)
assert.InDelta(t, test.rate, rate, 0.01)
}
}

Expand Down Expand Up @@ -89,7 +89,7 @@ func TestGetSamplingRate(t *testing.T) {
agent = NewAgentService(server.URL, zap.NewNop())
rate, err := agent.GetSamplingRate("svc", "op")
require.NoError(t, err)
assert.EqualValues(t, 1, rate)
assert.InDelta(t, 1.0, rate, 0.01)

_, err = agent.GetSamplingRate("bad_svc", "op")
require.Error(t, err)
Expand Down
12 changes: 6 additions & 6 deletions internal/metrics/otelmetrics/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestCounter(t *testing.T) {

testCounter := findMetric(t, registry, "test_counter_total")
metrics := testCounter.GetMetric()
assert.Equal(t, float64(2), metrics[0].GetCounter().GetValue())
assert.InDelta(t, float64(2), metrics[0].GetCounter().GetValue(), 0.01)
expectedLabels := map[string]string{
"tag1": "value1",
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestGauge(t *testing.T) {
testGauge := findMetric(t, registry, "test_gauge")

metrics := testGauge.GetMetric()
assert.Equal(t, float64(2), metrics[0].GetGauge().GetValue())
assert.InDelta(t, float64(2), metrics[0].GetGauge().GetValue(), 0.01)
expectedLabels := map[string]string{
"tag1": "value1",
}
Expand All @@ -148,7 +148,7 @@ func TestHistogram(t *testing.T) {
testHistogram := findMetric(t, registry, "test_histogram")

metrics := testHistogram.GetMetric()
assert.Equal(t, float64(1), metrics[0].GetHistogram().GetSampleSum())
assert.InDelta(t, float64(1), metrics[0].GetHistogram().GetSampleSum(), 0.01)
expectedLabels := map[string]string{
"tag1": "value1",
}
Expand All @@ -168,7 +168,7 @@ func TestTimer(t *testing.T) {
testTimer := findMetric(t, registry, "test_timer_seconds")

metrics := testTimer.GetMetric()
assert.Equal(t, float64(0.1), metrics[0].GetHistogram().GetSampleSum())
assert.InDelta(t, float64(0.1), metrics[0].GetHistogram().GetSampleSum(), 0.01)
expectedLabels := map[string]string{
"tag1": "value1",
}
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestNamespace(t *testing.T) {
testCounter := findMetric(t, registry, tc.expectedName)

metrics := testCounter.GetMetric()
assert.Equal(t, float64(1), metrics[0].GetCounter().GetValue())
assert.InDelta(t, float64(1), metrics[0].GetCounter().GetValue(), 0.01)
assert.Equal(t, tc.expectedLabels, promLabelsToMap(metrics[0].GetLabel()))
})
}
Expand All @@ -263,5 +263,5 @@ func TestNormalization(t *testing.T) {
testGauge := findMetric(t, registry, "My_Namespace_My_Gauge")

metrics := testGauge.GetMetric()
assert.Equal(t, float64(1), metrics[0].GetGauge().GetValue())
assert.InDelta(t, float64(1), metrics[0].GetGauge().GetValue(), 0.01)
}
6 changes: 3 additions & 3 deletions internal/metrics/prometheus/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestSeparator(t *testing.T) {
snapshot, err := registry.Gather()
require.NoError(t, err)
m1 := findMetric(t, snapshot, "bender:rodriguez_total", map[string]string{"a": "b"})
assert.EqualValues(t, 1, m1.GetCounter().GetValue(), "%+v", m1)
assert.InDelta(t, 1.0, m1.GetCounter().GetValue(), 0.01, "%+v", m1)
}

func TestCounter(t *testing.T) {
Expand Down Expand Up @@ -75,10 +75,10 @@ func TestCounter(t *testing.T) {
assert.EqualValues(t, "Help message", snapshot[0].GetHelp())

m1 := findMetric(t, snapshot, "bender_rodriguez_total", map[string]string{"a": "b", "x": "y"})
assert.EqualValues(t, 3, m1.GetCounter().GetValue(), "%+v", m1)
assert.InDelta(t, 3.0, m1.GetCounter().GetValue(), 0.01, "%+v", m1)

m2 := findMetric(t, snapshot, "bender_rodriguez_total", map[string]string{"a": "b", "x": "z"})
assert.EqualValues(t, 7, m2.GetCounter().GetValue(), "%+v", m2)
assert.InDelta(t, 7.0, m2.GetCounter().GetValue(), 0.01, "%+v", m2)
}

func TestCounterDefaultHelp(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion model/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func TestGetSamplerParams(t *testing.T) {
span.Tags = tt.tags
actualType, actualParam := span.GetSamplerParams(logger)
assert.Equal(t, tt.expectedType, actualType)
assert.Equal(t, tt.expectedParam, actualParam)
assert.InDelta(t, tt.expectedParam, actualParam, 0.01)
})
}
}
2 changes: 1 addition & 1 deletion plugin/metrics/prometheus/metricsstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ func assertMetrics(t *testing.T, gotMetrics *metrics.MetricFamily, wantLabels ma
assert.Equal(t, int64(1620351786), mps[0].Timestamp.GetSeconds())

actualVal := mps[0].Value.(*metrics.MetricPoint_GaugeValue).GaugeValue.Value.(*metrics.GaugeValue_DoubleValue).DoubleValue
assert.Equal(t, float64(9223372036854), actualVal)
assert.InDelta(t, float64(9223372036854), actualVal, 0.01)
}

func TestMain(m *testing.M) {
Expand Down
10 changes: 5 additions & 5 deletions plugin/sampling/strategyprovider/adaptive/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func TestFactory(t *testing.T) {

f.InitFromViper(v, zap.NewNop())

assert.Equal(t, 5.0, f.options.TargetSamplesPerSecond)
assert.Equal(t, 0.25, f.options.DeltaTolerance)
assert.InDelta(t, 5.0, f.options.TargetSamplesPerSecond, 0.01)
assert.InDelta(t, 0.25, f.options.DeltaTolerance, 0.001)
assert.Equal(t, int(2), f.options.BucketsForCalculation)
assert.Equal(t, time.Minute*15, f.options.CalculationInterval)
assert.Equal(t, int(3), f.options.AggregationBuckets)
assert.Equal(t, time.Minute*3, f.options.Delay)
assert.Equal(t, 0.02, f.options.InitialSamplingProbability)
assert.Equal(t, 0.01, f.options.MinSamplingProbability)
assert.Equal(t, 1.0, f.options.MinSamplesPerSecond)
assert.InDelta(t, 0.02, f.options.InitialSamplingProbability, 0.001)
assert.InDelta(t, 0.01, f.options.MinSamplingProbability, 0.001)
assert.InDelta(t, 1.0, f.options.MinSamplesPerSecond, 0.01)
assert.Equal(t, time.Second, f.options.LeaderLeaseRefreshInterval)
assert.Equal(t, time.Second*2, f.options.FollowerLeaseRefreshInterval)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ func TestInitializeThroughputFailure(t *testing.T) {

func TestCalculateQPS(t *testing.T) {
qps := calculateQPS(int64(90), 60*time.Second)
assert.Equal(t, 1.5, qps)
assert.InDelta(t, 1.5, qps, 0.01)

qps = calculateQPS(int64(45), 60*time.Second)
assert.Equal(t, 0.75, qps)
assert.InDelta(t, 0.75, qps, 0.01)
}

func TestGenerateOperationQPS(t *testing.T) {
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestCalculateWeightedQPS(t *testing.T) {
p := PostAggregator{weightVectorCache: NewWeightVectorCache()}
assert.InDelta(t, 0.86735, p.calculateWeightedQPS([]float64{0.8, 1.2, 1.0}), 0.001)
assert.InDelta(t, 0.95197, p.calculateWeightedQPS([]float64{1.0, 1.0, 0.0, 0.0}), 0.001)
assert.Equal(t, 0.0, p.calculateWeightedQPS([]float64{}))
assert.InDelta(t, 0.0, p.calculateWeightedQPS([]float64{}), 0.01)
}

func TestCalculateProbability(t *testing.T) {
Expand Down
32 changes: 16 additions & 16 deletions plugin/sampling/strategyprovider/static/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,17 @@ func TestPerOperationSamplingStrategies(t *testing.T) {

require.NotNil(t, s.OperationSampling)
os := s.OperationSampling
assert.EqualValues(t, 0.8, os.DefaultSamplingProbability)
assert.InDelta(t, 0.8, os.DefaultSamplingProbability, 0.01)
require.Len(t, os.PerOperationStrategies, 4)

assert.Equal(t, "op6", os.PerOperationStrategies[0].Operation)
assert.EqualValues(t, 0.5, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 0.5, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate, 0.01)
assert.Equal(t, "op1", os.PerOperationStrategies[1].Operation)
assert.EqualValues(t, 0.2, os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 0.2, os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate, 0.01)
assert.Equal(t, "op0", os.PerOperationStrategies[2].Operation)
assert.EqualValues(t, 0.2, os.PerOperationStrategies[2].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 0.2, os.PerOperationStrategies[2].ProbabilisticSampling.SamplingRate, 0.01)
assert.Equal(t, "op7", os.PerOperationStrategies[3].Operation)
assert.EqualValues(t, 1, os.PerOperationStrategies[3].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 1.0, os.PerOperationStrategies[3].ProbabilisticSampling.SamplingRate, 0.01)

expected = makeResponse(api_v2.SamplingStrategyType_RATE_LIMITING, 5)

Expand All @@ -200,18 +200,18 @@ func TestPerOperationSamplingStrategies(t *testing.T) {

require.NotNil(t, s.OperationSampling)
os = s.OperationSampling
assert.EqualValues(t, 0.001, os.DefaultSamplingProbability)
assert.InEpsilon(t, 0.001, os.DefaultSamplingProbability, 0.0001)
require.Len(t, os.PerOperationStrategies, 5)
assert.Equal(t, "op3", os.PerOperationStrategies[0].Operation)
assert.EqualValues(t, 0.3, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 0.3, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate, 0.01)
assert.Equal(t, "op5", os.PerOperationStrategies[1].Operation)
assert.EqualValues(t, 0.4, os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 0.4, os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate, 0.01)
assert.Equal(t, "op0", os.PerOperationStrategies[2].Operation)
assert.EqualValues(t, 0.2, os.PerOperationStrategies[2].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 0.2, os.PerOperationStrategies[2].ProbabilisticSampling.SamplingRate, 0.01)
assert.Equal(t, "op6", os.PerOperationStrategies[3].Operation)
assert.EqualValues(t, 0, os.PerOperationStrategies[3].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 0.0, os.PerOperationStrategies[3].ProbabilisticSampling.SamplingRate, 0.01)
assert.Equal(t, "op7", os.PerOperationStrategies[4].Operation)
assert.EqualValues(t, 1, os.PerOperationStrategies[4].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 1.0, os.PerOperationStrategies[4].ProbabilisticSampling.SamplingRate, 0.01)

s, err = provider.GetSamplingStrategy(context.Background(), "default")
require.NoError(t, err)
Expand Down Expand Up @@ -258,10 +258,10 @@ func TestMissingServiceSamplingStrategyTypes(t *testing.T) {

require.NotNil(t, s.OperationSampling)
os := s.OperationSampling
assert.EqualValues(t, defaultSamplingProbability, os.DefaultSamplingProbability)
assert.InEpsilon(t, defaultSamplingProbability, os.DefaultSamplingProbability, 0.0001)
require.Len(t, os.PerOperationStrategies, 1)
assert.Equal(t, "op1", os.PerOperationStrategies[0].Operation)
assert.EqualValues(t, 0.2, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 0.2, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate, 0.001)

expected = makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, defaultSamplingProbability)

Expand All @@ -272,12 +272,12 @@ func TestMissingServiceSamplingStrategyTypes(t *testing.T) {

require.NotNil(t, s.OperationSampling)
os = s.OperationSampling
assert.EqualValues(t, 0.001, os.DefaultSamplingProbability)
assert.InEpsilon(t, 0.001, os.DefaultSamplingProbability, 0.0001)
require.Len(t, os.PerOperationStrategies, 2)
assert.Equal(t, "op3", os.PerOperationStrategies[0].Operation)
assert.EqualValues(t, 0.3, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 0.3, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate, 0.01)
assert.Equal(t, "op5", os.PerOperationStrategies[1].Operation)
assert.EqualValues(t, 0.4, os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate)
assert.InDelta(t, 0.4, os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate, 0.01)

s, err = provider.GetSamplingStrategy(context.Background(), "default")
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/cassandra/samplingstore/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func TestGetLatestProbabilities(t *testing.T) {

if testCase.expectedError == "" {
require.NoError(t, err)
assert.Equal(t, 0.84, probabilities["svc"]["op"])
assert.InDelta(t, 0.84, probabilities["svc"]["op"], 0.01)
} else {
require.EqualError(t, err, testCase.expectedError)
}
Expand Down
6 changes: 3 additions & 3 deletions plugin/storage/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,15 @@ func TestParsingDownsamplingRatio(t *testing.T) {
require.NoError(t, err)
f.InitFromViper(v, zap.NewNop())

assert.Equal(t, 1.0, f.FactoryConfig.DownsamplingRatio)
assert.InDelta(t, 1.0, f.FactoryConfig.DownsamplingRatio, 0.01)
assert.Equal(t, "jaeger", f.FactoryConfig.DownsamplingHashSalt)

err = command.ParseFlags([]string{
"--downsampling.ratio=0.5",
})
require.NoError(t, err)
f.InitFromViper(v, zap.NewNop())
assert.Equal(t, 0.5, f.FactoryConfig.DownsamplingRatio)
assert.InDelta(t, 0.5, f.FactoryConfig.DownsamplingRatio, 0.01)
}

func TestDefaultDownsamplingWithAddFlags(t *testing.T) {
Expand All @@ -384,7 +384,7 @@ func TestDefaultDownsamplingWithAddFlags(t *testing.T) {
require.NoError(t, err)
f.InitFromViper(v, zap.NewNop())

assert.Equal(t, defaultDownsamplingRatio, f.FactoryConfig.DownsamplingRatio)
assert.InDelta(t, defaultDownsamplingRatio, f.FactoryConfig.DownsamplingRatio, 0.01)
assert.Equal(t, defaultDownsamplingHashSalt, f.FactoryConfig.DownsamplingHashSalt)

err = command.ParseFlags([]string{
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/memory/sampling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestInsertProbabilitiesAndQPS(t *testing.T) {
assert.NotEmpty(t, 1, samplingStore.probabilitiesAndQPS)
// Only latest one is kept in memory
require.NoError(t, samplingStore.InsertProbabilitiesAndQPS("lncol73", model.ServiceOperationProbabilities{"my-app": {"hello": 0.3}}, model.ServiceOperationQPS{"new-srv": {"op": 7}}))
assert.Equal(t, 0.3, samplingStore.probabilitiesAndQPS.probabilities["my-app"]["hello"])
assert.InDelta(t, 0.3, samplingStore.probabilitiesAndQPS.probabilities["my-app"]["hello"], 0.01)
})
}

Expand Down

0 comments on commit 57d95f3

Please sign in to comment.