From 1dd5a24f4e9ff8233143559af19f0af846f5e43b Mon Sep 17 00:00:00 2001 From: Zane Dufour Date: Mon, 18 Nov 2024 16:09:18 -0500 Subject: [PATCH] fix: switch [][]byte split support to []byte --- pkg/ottl/expression.go | 2 +- pkg/ottl/expression_test.go | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pkg/ottl/expression.go b/pkg/ottl/expression.go index fb8a8617a77a..a2e8d29e63c4 100644 --- a/pkg/ottl/expression.go +++ b/pkg/ottl/expression.go @@ -135,7 +135,7 @@ func (g exprGetter[K]) Get(ctx context.Context, tCtx K) (any, error) { if err != nil { return nil, err } - case [][]byte: + case []byte: result, err = getElementByIndex(r, k.Int) if err != nil { return nil, err diff --git a/pkg/ottl/expression_test.go b/pkg/ottl/expression_test.go index 829e86201bc1..e5cffbfcd547 100644 --- a/pkg/ottl/expression_test.go +++ b/pkg/ottl/expression_test.go @@ -99,11 +99,11 @@ func basicSliceFloat() (ExprFunc[any], error) { }, nil } -func basicSliceBytes() (ExprFunc[any], error) { +func basicSliceByte() (ExprFunc[any], error) { return func(_ context.Context, _ any) (any, error) { return []any{ - [][]byte{ - []byte("pass"), + []byte{ + byte('p'), }, }, nil }, nil @@ -314,7 +314,6 @@ func Test_newGetter(t *testing.T) { Function: "SliceBool", Keys: []key{ { - // note for review: not sure if this is correct Int: ottltest.Intp(0), }, { @@ -334,7 +333,6 @@ func Test_newGetter(t *testing.T) { Function: "SliceInteger", Keys: []key{ { - // note for review: not sure if this is correct Int: ottltest.Intp(0), }, { @@ -354,7 +352,6 @@ func Test_newGetter(t *testing.T) { Function: "SliceFloat", Keys: []key{ { - // note for review: not sure if this is correct Int: ottltest.Intp(0), }, { @@ -367,14 +364,13 @@ func Test_newGetter(t *testing.T) { want: 1.0, }, { - name: "function call nested SliceBytes", + name: "function call nested SliceByte", val: value{ Literal: &mathExprLiteral{ Converter: &converter{ - Function: "SliceBytes", + Function: "SliceByte", Keys: []key{ { - // note for review: not sure if this is correct Int: ottltest.Intp(0), }, { @@ -384,7 +380,7 @@ func Test_newGetter(t *testing.T) { }, }, }, - want: []byte("pass"), + want: byte('p'), }, { name: "enum", @@ -685,7 +681,7 @@ func Test_newGetter(t *testing.T) { createFactory("SliceBool", &struct{}{}, basicSliceBool), createFactory("SliceInteger", &struct{}{}, basicSliceInteger), createFactory("SliceFloat", &struct{}{}, basicSliceFloat), - createFactory("SliceBytes", &struct{}{}, basicSliceBytes), + createFactory("SliceByte", &struct{}{}, basicSliceByte), ) p, _ := NewParser[any](