@@ -534,7 +534,13 @@ func Test_replaceAllPatterns(t *testing.T) {
534534 },
535535 }
536536
537- exprFunc , err := replaceAllPatterns [pcommon.Map ](target , tt .mode , tt .pattern , tt .replacement , tt .function , tt .replacementFormat )
537+ pattern := & ottl.StandardStringGetter [pcommon.Map ]{
538+ Getter : func (_ context.Context , _ pcommon.Map ) (any , error ) {
539+ return tt .pattern , nil
540+ },
541+ }
542+
543+ exprFunc , err := replaceAllPatterns [pcommon.Map ](target , tt .mode , pattern , tt .replacement , tt .function , tt .replacementFormat )
538544 assert .NoError (t , err )
539545
540546 _ , err = exprFunc (nil , scenarioMap )
@@ -567,7 +573,13 @@ func Test_replaceAllPatterns_bad_input(t *testing.T) {
567573 function := ottl.Optional [ottl.FunctionGetter [any ]]{}
568574 replacementFormat := ottl.Optional [ottl.StringGetter [any ]]{}
569575
570- exprFunc , err := replaceAllPatterns [any ](target , modeValue , "regexpattern" , replacement , function , replacementFormat )
576+ pattern := & ottl.StandardStringGetter [any ]{
577+ Getter : func (_ context.Context , _ any ) (any , error ) {
578+ return "regexpattern" , nil
579+ },
580+ }
581+
582+ exprFunc , err := replaceAllPatterns [any ](target , modeValue , pattern , replacement , function , replacementFormat )
571583 assert .NoError (t , err )
572584
573585 _ , err = exprFunc (nil , input )
@@ -592,7 +604,13 @@ func Test_replaceAllPatterns_bad_function_input(t *testing.T) {
592604 function := ottl.Optional [ottl.FunctionGetter [any ]]{}
593605 replacementFormat := ottl.Optional [ottl.StringGetter [any ]]{}
594606
595- exprFunc , err := replaceAllPatterns [any ](target , modeValue , "regexp" , replacement , function , replacementFormat )
607+ pattern := & ottl.StandardStringGetter [any ]{
608+ Getter : func (_ context.Context , _ any ) (any , error ) {
609+ return "regexp" , nil
610+ },
611+ }
612+
613+ exprFunc , err := replaceAllPatterns [any ](target , modeValue , pattern , replacement , function , replacementFormat )
596614 assert .NoError (t , err )
597615
598616 result , err := exprFunc (nil , input )
@@ -634,7 +652,13 @@ func Test_replaceAllPatterns_bad_function_result(t *testing.T) {
634652 function := ottl.NewTestingOptional [ottl.FunctionGetter [any ]](ottlValue )
635653 replacementFormat := ottl.Optional [ottl.StringGetter [any ]]{}
636654
637- exprFunc , err := replaceAllPatterns [any ](target , modeValue , "regexp" , replacement , function , replacementFormat )
655+ pattern := & ottl.StandardStringGetter [any ]{
656+ Getter : func (_ context.Context , _ any ) (any , error ) {
657+ return "regexp" , nil
658+ },
659+ }
660+
661+ exprFunc , err := replaceAllPatterns [any ](target , modeValue , pattern , replacement , function , replacementFormat )
638662 assert .NoError (t , err )
639663
640664 result , err := exprFunc (nil , input )
@@ -666,7 +690,13 @@ func Test_replaceAllPatterns_get_nil(t *testing.T) {
666690 function := ottl.Optional [ottl.FunctionGetter [any ]]{}
667691 replacementFormat := ottl.Optional [ottl.StringGetter [any ]]{}
668692
669- exprFunc , err := replaceAllPatterns [any ](target , modeValue , "regexp" , replacement , function , replacementFormat )
693+ pattern := & ottl.StandardStringGetter [any ]{
694+ Getter : func (_ context.Context , _ any ) (any , error ) {
695+ return "regexp" , nil
696+ },
697+ }
698+
699+ exprFunc , err := replaceAllPatterns [any ](target , modeValue , pattern , replacement , function , replacementFormat )
670700 assert .NoError (t , err )
671701
672702 _ , err = exprFunc (nil , nil )
@@ -676,7 +706,7 @@ func Test_replaceAllPatterns_get_nil(t *testing.T) {
676706func Test_replaceAllPatterns_invalid_pattern (t * testing.T ) {
677707 target := & ottl.StandardPMapGetSetter [any ]{
678708 Getter : func (context.Context , any ) (pcommon.Map , error ) {
679- return pcommon.Map {}, errors . New ( "nothing should be received in this scenario" )
709+ return pcommon.Map {}, nil
680710 },
681711 }
682712 replacement := & ottl.StandardStringGetter [any ]{
@@ -687,11 +717,15 @@ func Test_replaceAllPatterns_invalid_pattern(t *testing.T) {
687717 function := ottl.Optional [ottl.FunctionGetter [any ]]{}
688718 replacementFormat := ottl.Optional [ottl.StringGetter [any ]]{}
689719
690- invalidRegexPattern := "*"
691- exprFunc , err := replaceAllPatterns [any ](target , modeValue , invalidRegexPattern , replacement , function , replacementFormat )
692- require .Error (t , err )
720+ pattern := & ottl.StandardStringGetter [any ]{
721+ Getter : func (_ context.Context , _ any ) (any , error ) {
722+ return "*" , nil
723+ },
724+ }
725+ exprFunc , err := replaceAllPatterns [any ](target , modeValue , pattern , replacement , function , replacementFormat )
726+ require .NoError (t , err )
727+ _ , err = exprFunc (nil , nil )
693728 assert .ErrorContains (t , err , "error parsing regexp:" )
694- assert .Nil (t , exprFunc )
695729}
696730
697731func Test_replaceAllPatterns_invalid_model (t * testing.T ) {
@@ -709,7 +743,12 @@ func Test_replaceAllPatterns_invalid_model(t *testing.T) {
709743 replacementFormat := ottl.Optional [ottl.StringGetter [any ]]{}
710744
711745 invalidMode := "invalid"
712- exprFunc , err := replaceAllPatterns [any ](target , invalidMode , "regex" , replacement , function , replacementFormat )
746+ pattern := & ottl.StandardStringGetter [any ]{
747+ Getter : func (_ context.Context , _ any ) (any , error ) {
748+ return "regex" , nil
749+ },
750+ }
751+ exprFunc , err := replaceAllPatterns [any ](target , invalidMode , pattern , replacement , function , replacementFormat )
713752 assert .Nil (t , exprFunc )
714753 assert .ErrorContains (t , err , "invalid mode" )
715754}
0 commit comments