Skip to content

Commit

Permalink
Replace interface{} to any
Browse files Browse the repository at this point in the history
Replace interface{} to any according to PR 29072.
  • Loading branch information
Dennis40816 committed Nov 12, 2023
1 parent cb80186 commit 6cdf739
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions pkg/ottl/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
74 changes: 37 additions & 37 deletions pkg/ottl/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
Expand All @@ -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
},
},
Expand All @@ -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
},
},
Expand All @@ -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
},
},
Expand All @@ -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("")
},
}
Expand All @@ -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
},
},
Expand All @@ -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
},
},
Expand All @@ -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
},
},
Expand All @@ -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
},
},
Expand All @@ -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
},
Expand All @@ -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
},
Expand All @@ -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
},
Expand All @@ -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
},
Expand All @@ -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
},
},
Expand All @@ -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
},
},
Expand All @@ -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
},
Expand Down Expand Up @@ -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("")
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ottl/ottlfuncs/func_is_bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/ottl/ottlfuncs/func_is_bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func Test_IsBool(t *testing.T) {
tests := []struct {
name string
value interface{}
value any
expected bool
}{
{
Expand Down Expand Up @@ -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
},
})
Expand All @@ -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("")
},
})
Expand Down

0 comments on commit 6cdf739

Please sign in to comment.