@@ -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+ target := ottl.StandardGetSetter [any ]{
344345 Getter : func (_ context.Context , _ any ) (any , 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 ]{
503+ target := ottl.StandardGetSetter [any ]{
494504 Getter : func (_ context.Context , _ any ) (any , 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 ))
@@ -510,7 +529,7 @@ func Test_flatten_undeterministic(t *testing.T) {
510529}
511530
512531func Test_flatten_bad_target (t * testing.T ) {
513- target := & ottl.StandardPMapGetter [any ]{
532+ target := & ottl.StandardGetSetter [any ]{
514533 Getter : func (_ context.Context , _ any ) (any , error ) {
515534 return 1 , nil
516535 },
@@ -538,7 +557,7 @@ func Test_flatten_bad_depth(t *testing.T) {
538557
539558 for _ , tt := range tests {
540559 t .Run (tt .name , func (t * testing.T ) {
541- target := & ottl.StandardPMapGetter [any ]{
560+ target := & ottl.StandardGetSetter [any ]{
542561 Getter : func (_ context.Context , _ any ) (any , error ) {
543562 return pcommon .NewMap (), nil
544563 },
0 commit comments