mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-21 23:00:42 -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:
@@ -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