From 6cdf73959f1e223e5dc8f59992049c2624166d8e Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Sun, 12 Nov 2023 12:39:03 +0800 Subject: [PATCH] Replace interface{} to any Replace interface{} to any according to PR 29072. --- pkg/ottl/expression.go | 4 +- pkg/ottl/expression_test.go | 74 ++++++++++++------------- pkg/ottl/ottlfuncs/func_is_bool.go | 2 +- pkg/ottl/ottlfuncs/func_is_bool_test.go | 6 +- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/pkg/ottl/expression.go b/pkg/ottl/expression.go index b52b134951c6..1c5ac3f69b17 100644 --- a/pkg/ottl/expression.go +++ b/pkg/ottl/expression.go @@ -255,7 +255,7 @@ type BoolGetter[K any] interface { // StandardBoolGetter is a basic implementation of BoolGetter type StandardBoolGetter[K any] struct { - Getter func(ctx context.Context, tCtx K) (interface{}, error) + Getter func(ctx context.Context, tCtx K) (any, error) } // Get retrieves a bool value. @@ -552,7 +552,7 @@ type BoolLikeGetter[K any] interface { } type StandardBoolLikeGetter[K any] struct { - Getter func(ctx context.Context, tCtx K) (interface{}, error) + Getter func(ctx context.Context, tCtx K) (any, error) } func (g StandardBoolLikeGetter[K]) Get(ctx context.Context, tCtx K) (*bool, error) { diff --git a/pkg/ottl/expression_test.go b/pkg/ottl/expression_test.go index 54b956220b23..478d56defead 100644 --- a/pkg/ottl/expression_test.go +++ b/pkg/ottl/expression_test.go @@ -1452,15 +1452,15 @@ func Test_StandardIntLikeGetter_WrappedError(t *testing.T) { func Test_StandardBoolGetter(t *testing.T) { tests := []struct { name string - getter StandardBoolGetter[interface{}] + getter StandardBoolGetter[any] want bool valid bool expectedErrorMsg string }{ { name: "primitive bool type", - getter: StandardBoolGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return true, nil }, }, @@ -1469,8 +1469,8 @@ func Test_StandardBoolGetter(t *testing.T) { }, { name: "ValueTypeBool type", - getter: StandardBoolGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return pcommon.NewValueBool(true), nil }, }, @@ -1479,8 +1479,8 @@ func Test_StandardBoolGetter(t *testing.T) { }, { name: "Incorrect type", - getter: StandardBoolGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return 1, nil }, }, @@ -1489,8 +1489,8 @@ func Test_StandardBoolGetter(t *testing.T) { }, { name: "nil", - getter: StandardBoolGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return nil, nil }, }, @@ -1515,8 +1515,8 @@ func Test_StandardBoolGetter(t *testing.T) { // nolint:errorlint func Test_StandardBoolGetter_WrappedError(t *testing.T) { - getter := StandardBoolGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter := StandardBoolGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return nil, TypeError("") }, } @@ -1529,15 +1529,15 @@ func Test_StandardBoolGetter_WrappedError(t *testing.T) { func Test_StandardBoolLikeGetter(t *testing.T) { tests := []struct { name string - getter BoolLikeGetter[interface{}] - want interface{} + getter BoolLikeGetter[any] + want any valid bool expectedErrorMsg string }{ { name: "string type true", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return "true", nil }, }, @@ -1546,8 +1546,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { }, { name: "string type false", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return "false", nil }, }, @@ -1556,8 +1556,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { }, { name: "int type", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return 0, nil }, }, @@ -1566,8 +1566,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { }, { name: "float64 type", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return float64(0.0), nil }, }, @@ -1576,8 +1576,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { }, { name: "pcommon.value type int", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { v := pcommon.NewValueInt(int64(0)) return v, nil }, @@ -1587,8 +1587,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { }, { name: "pcommon.value type string", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { v := pcommon.NewValueStr("false") return v, nil }, @@ -1598,8 +1598,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { }, { name: "pcommon.value type bool", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { v := pcommon.NewValueBool(true) return v, nil }, @@ -1609,8 +1609,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { }, { name: "pcommon.value type double", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { v := pcommon.NewValueDouble(float64(0.0)) return v, nil }, @@ -1620,8 +1620,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { }, { name: "nil", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return nil, nil }, }, @@ -1630,8 +1630,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { }, { name: "invalid type", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return []byte{}, nil }, }, @@ -1640,8 +1640,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { }, { name: "invalid pcommon.value type", - getter: StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter: StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { v := pcommon.NewValueMap() return v, nil }, @@ -1671,8 +1671,8 @@ func Test_StandardBoolLikeGetter(t *testing.T) { // nolint:errorlint func Test_StandardBoolLikeGetter_WrappedError(t *testing.T) { - getter := StandardBoolLikeGetter[interface{}]{ - Getter: func(ctx context.Context, tCtx interface{}) (interface{}, error) { + getter := StandardBoolLikeGetter[any]{ + Getter: func(ctx context.Context, tCtx any) (any, error) { return nil, TypeError("") }, } diff --git a/pkg/ottl/ottlfuncs/func_is_bool.go b/pkg/ottl/ottlfuncs/func_is_bool.go index b62866e0ab62..b2845e919c33 100644 --- a/pkg/ottl/ottlfuncs/func_is_bool.go +++ b/pkg/ottl/ottlfuncs/func_is_bool.go @@ -30,7 +30,7 @@ func createIsBoolFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments) ( // nolint:errorlint func isBool[K any](target ottl.BoolGetter[K]) ottl.ExprFunc[K] { - return func(ctx context.Context, tCtx K) (interface{}, error) { + return func(ctx context.Context, tCtx K) (any, error) { _, err := target.Get(ctx, tCtx) // Use type assertion, because we don't want to check wrapped errors switch err.(type) { diff --git a/pkg/ottl/ottlfuncs/func_is_bool_test.go b/pkg/ottl/ottlfuncs/func_is_bool_test.go index 780ab61139d5..4cb780385923 100644 --- a/pkg/ottl/ottlfuncs/func_is_bool_test.go +++ b/pkg/ottl/ottlfuncs/func_is_bool_test.go @@ -16,7 +16,7 @@ import ( func Test_IsBool(t *testing.T) { tests := []struct { name string - value interface{} + value any expected bool }{ { @@ -48,7 +48,7 @@ func Test_IsBool(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { exprFunc := isBool[any](&ottl.StandardBoolGetter[any]{ - Getter: func(context.Context, interface{}) (interface{}, error) { + Getter: func(context.Context, any) (any, error) { return tt.value, nil }, }) @@ -62,7 +62,7 @@ func Test_IsBool(t *testing.T) { // nolint:errorlint func Test_IsBool_Error(t *testing.T) { exprFunc := isBool[any](&ottl.StandardBoolGetter[any]{ - Getter: func(context.Context, interface{}) (interface{}, error) { + Getter: func(context.Context, any) (any, error) { return nil, ottl.TypeError("") }, })