mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-06 04:41:18 -08:00
chore: enable float-compare rule from testifylint (#6967)
Signed-off-by: knqyf263 <knqyf263@gmail.com> Co-authored-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
@@ -84,9 +84,6 @@ linters-settings:
|
||||
ignore-generated-header: true
|
||||
testifylint:
|
||||
enable-all: true
|
||||
disable:
|
||||
- float-compare
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
|
||||
@@ -24,7 +24,7 @@ func Test_Number_IntToFloat(t *testing.T) {
|
||||
metadata := types.NewTestMetadata()
|
||||
err := Unmarshal(example, &output, &metadata)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 123.0, output)
|
||||
assert.InEpsilon(t, 123.0, output, 0.0001)
|
||||
}
|
||||
|
||||
func Test_Number_FloatToFloat(t *testing.T) {
|
||||
@@ -33,7 +33,7 @@ func Test_Number_FloatToFloat(t *testing.T) {
|
||||
metadata := types.NewTestMetadata()
|
||||
err := Unmarshal(example, &output, &metadata)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 123.456, output)
|
||||
assert.InEpsilon(t, 123.456, output, 0.0001)
|
||||
}
|
||||
|
||||
func Test_Number_FloatToInt(t *testing.T) {
|
||||
@@ -42,7 +42,7 @@ func Test_Number_FloatToInt(t *testing.T) {
|
||||
metadata := types.NewTestMetadata()
|
||||
err := Unmarshal(example, &output, &metadata)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 123, output)
|
||||
assert.InEpsilon(t, 123, output, 0.0001)
|
||||
}
|
||||
|
||||
func Test_Number_FloatWithExponent(t *testing.T) {
|
||||
@@ -70,7 +70,7 @@ func Test_Number_FloatWithExponent(t *testing.T) {
|
||||
metadata := types.NewTestMetadata()
|
||||
err := Unmarshal(example, &output, &metadata)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.out, output)
|
||||
assert.InEpsilon(t, test.out, output, 0.0001)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func Test_Object(t *testing.T) {
|
||||
metadata := types.NewTestMetadata()
|
||||
require.NoError(t, Unmarshal(example, &target, &metadata))
|
||||
assert.Equal(t, "testing", target.Name)
|
||||
assert.Equal(t, 3.14, target.Balance)
|
||||
assert.InEpsilon(t, 3.14, target.Balance, 0.0001)
|
||||
}
|
||||
|
||||
func Test_ObjectWithPointers(t *testing.T) {
|
||||
@@ -36,7 +36,7 @@ func Test_ObjectWithPointers(t *testing.T) {
|
||||
metadata := types.NewTestMetadata()
|
||||
require.NoError(t, Unmarshal(example, &target, &metadata))
|
||||
assert.Equal(t, "testing", *target.Name)
|
||||
assert.Equal(t, 3.14, *target.Balance)
|
||||
assert.InEpsilon(t, 3.14, *target.Balance, 0.0001)
|
||||
}
|
||||
|
||||
type nestedParent struct {
|
||||
|
||||
@@ -410,7 +410,7 @@ func TestJsonWithNumbers(t *testing.T) {
|
||||
file := files[0]
|
||||
|
||||
assert.Equal(t, 1, file.Parameters["SomeIntParam"].Default())
|
||||
assert.Equal(t, 1.1, file.Parameters["SomeFloatParam"].Default())
|
||||
assert.InEpsilon(t, 1.1, file.Parameters["SomeFloatParam"].Default(), 0.0001)
|
||||
|
||||
res := file.GetResourcesByType("Test::Resource")
|
||||
assert.NotNil(t, res)
|
||||
|
||||
@@ -34,7 +34,7 @@ func Test_Parser(t *testing.T) {
|
||||
y, ok := yRaw.(float64)
|
||||
require.True(t, ok)
|
||||
|
||||
assert.Equal(t, 123.0, y)
|
||||
assert.InEpsilon(t, 123.0, y, 0.0001)
|
||||
|
||||
zRaw, ok := xMsi["z"]
|
||||
require.True(t, ok)
|
||||
|
||||
@@ -3,7 +3,6 @@ package parallel_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -15,13 +14,13 @@ import (
|
||||
func TestPipeline_Do(t *testing.T) {
|
||||
type field struct {
|
||||
numWorkers int
|
||||
items []float64
|
||||
onItem func(context.Context, float64) (float64, error)
|
||||
items []int
|
||||
onItem func(context.Context, int) (int, error)
|
||||
}
|
||||
type testCase struct {
|
||||
name string
|
||||
field field
|
||||
want float64
|
||||
want int
|
||||
wantErr require.ErrorAssertionFunc
|
||||
}
|
||||
tests := []testCase{
|
||||
@@ -29,7 +28,7 @@ func TestPipeline_Do(t *testing.T) {
|
||||
name: "pow",
|
||||
field: field{
|
||||
numWorkers: 5,
|
||||
items: []float64{
|
||||
items: []int{
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
@@ -41,44 +40,44 @@ func TestPipeline_Do(t *testing.T) {
|
||||
9,
|
||||
10,
|
||||
},
|
||||
onItem: func(_ context.Context, f float64) (float64, error) {
|
||||
return math.Pow(f, 2), nil
|
||||
onItem: func(_ context.Context, i int) (int, error) {
|
||||
return i * i, nil
|
||||
},
|
||||
},
|
||||
want: 385,
|
||||
wantErr: require.NoError,
|
||||
},
|
||||
{
|
||||
name: "ceil",
|
||||
name: "double",
|
||||
field: field{
|
||||
numWorkers: 3,
|
||||
items: []float64{
|
||||
1.1,
|
||||
2.2,
|
||||
3.3,
|
||||
4.4,
|
||||
5.5,
|
||||
-1.1,
|
||||
-2.2,
|
||||
-3.3,
|
||||
items: []int{
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
-1,
|
||||
-2,
|
||||
-3,
|
||||
},
|
||||
onItem: func(_ context.Context, f float64) (float64, error) {
|
||||
return math.Round(f), nil
|
||||
onItem: func(_ context.Context, i int) (int, error) {
|
||||
return i * 2, nil
|
||||
},
|
||||
},
|
||||
want: 10,
|
||||
want: 18,
|
||||
wantErr: require.NoError,
|
||||
},
|
||||
{
|
||||
name: "error in series",
|
||||
field: field{
|
||||
numWorkers: 1,
|
||||
items: []float64{
|
||||
items: []int{
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
},
|
||||
onItem: func(_ context.Context, f float64) (float64, error) {
|
||||
onItem: func(_ context.Context, _ int) (int, error) {
|
||||
return 0, fmt.Errorf("error")
|
||||
},
|
||||
},
|
||||
@@ -88,11 +87,11 @@ func TestPipeline_Do(t *testing.T) {
|
||||
name: "error in parallel",
|
||||
field: field{
|
||||
numWorkers: 3,
|
||||
items: []float64{
|
||||
items: []int{
|
||||
1,
|
||||
2,
|
||||
},
|
||||
onItem: func(_ context.Context, f float64) (float64, error) {
|
||||
onItem: func(_ context.Context, _ int) (int, error) {
|
||||
return 0, fmt.Errorf("error")
|
||||
},
|
||||
},
|
||||
@@ -101,8 +100,8 @@ func TestPipeline_Do(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var got float64
|
||||
p := parallel.NewPipeline(tt.field.numWorkers, false, tt.field.items, tt.field.onItem, func(f float64) error {
|
||||
var got int
|
||||
p := parallel.NewPipeline(tt.field.numWorkers, false, tt.field.items, tt.field.onItem, func(f int) error {
|
||||
got += f
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user