@@ -5,6 +5,7 @@ package ottlfuncs
55
66import (
77 "context"
8+ "errors"
89 "reflect"
910 "testing"
1011
@@ -340,10 +341,19 @@ func Test_flatten(t *testing.T) {
340341 m := pcommon .NewMap ()
341342 err := m .FromRaw (tt .target )
342343 assert .NoError (t , err )
343- target := ottl.StandardPMapGetter [any ]{
344- Getter : func (_ context.Context , _ any ) (any , error ) {
344+ target := ottl.StandardPMapGetSetter [any ]{
345+ Getter : func (_ context.Context , _ any ) (pcommon. Map , error ) {
345346 return m , nil
346347 },
348+ Setter : func (_ context.Context , _ any , m any ) error {
349+ if v , ok := m .(pcommon.Map ); ok {
350+ if dst , ok2 := m .(pcommon.Map ); ok2 {
351+ v .CopyTo (dst )
352+ return nil
353+ }
354+ }
355+ return errors .New ("expected pcommon.Map" )
356+ },
347357 }
348358
349359 exprFunc , err := flatten [any ](target , tt .prefix , tt .depth , ottl.NewTestingOptional [bool ](tt .conflict ))
@@ -490,10 +500,19 @@ func Test_flatten_undeterministic(t *testing.T) {
490500 m := pcommon .NewMap ()
491501 err := m .FromRaw (tt .target )
492502 assert .NoError (t , err )
493- target := ottl.StandardPMapGetter [any ]{
494- Getter : func (_ context.Context , _ any ) (any , error ) {
503+ target := ottl.StandardPMapGetSetter [any ]{
504+ Getter : func (_ context.Context , _ any ) (pcommon. Map , error ) {
495505 return m , nil
496506 },
507+ Setter : func (_ context.Context , tCtx any , m any ) error {
508+ if v , ok := m .(pcommon.Map ); ok {
509+ if dst , ok2 := tCtx .(pcommon.Map ); ok2 {
510+ v .CopyTo (dst )
511+ }
512+ return nil
513+ }
514+ return errors .New ("expected pcommon.Map" )
515+ },
497516 }
498517
499518 exprFunc , err := flatten [any ](target , tt .prefix , tt .depth , ottl.NewTestingOptional [bool ](tt .conflict ))
@@ -509,18 +528,6 @@ func Test_flatten_undeterministic(t *testing.T) {
509528 }
510529}
511530
512- func Test_flatten_bad_target (t * testing.T ) {
513- target := & ottl.StandardPMapGetter [any ]{
514- Getter : func (_ context.Context , _ any ) (any , error ) {
515- return 1 , nil
516- },
517- }
518- exprFunc , err := flatten [any ](target , ottl.Optional [string ]{}, ottl.Optional [int64 ]{}, ottl.NewTestingOptional [bool ](false ))
519- assert .NoError (t , err )
520- _ , err = exprFunc (nil , nil )
521- assert .Error (t , err )
522- }
523-
524531func Test_flatten_bad_depth (t * testing.T ) {
525532 tests := []struct {
526533 name string
@@ -538,8 +545,8 @@ func Test_flatten_bad_depth(t *testing.T) {
538545
539546 for _ , tt := range tests {
540547 t .Run (tt .name , func (t * testing.T ) {
541- target := & ottl.StandardPMapGetter [any ]{
542- Getter : func (_ context.Context , _ any ) (any , error ) {
548+ target := & ottl.StandardPMapGetSetter [any ]{
549+ Getter : func (_ context.Context , _ any ) (pcommon. Map , error ) {
543550 return pcommon .NewMap (), nil
544551 },
545552 }
0 commit comments