@@ -58,14 +58,6 @@ func Test_keepMatchingKeys(t *testing.T) {
5858 return & m
5959 },
6060 },
61- {
62- name : "invalid pattern" ,
63- pattern : "*" ,
64- want : func () * pcommon.Map {
65- return nil
66- },
67- wantError : true ,
68- },
6961 }
7062 for _ , tt := range tests {
7163 t .Run (tt .name , func (t * testing.T ) {
@@ -87,7 +79,12 @@ func Test_keepMatchingKeys(t *testing.T) {
8779 },
8880 }
8981
90- exprFunc , err := keepMatchingKeys (target , tt .pattern )
82+ pattern := & ottl.StandardStringGetter [pcommon.Map ]{
83+ Getter : func (_ context.Context , _ pcommon.Map ) (any , error ) {
84+ return tt .pattern , nil
85+ },
86+ }
87+ exprFunc , err := keepMatchingKeys (target , pattern )
9188
9289 if tt .wantError {
9390 assert .Error (t , err )
@@ -115,7 +112,37 @@ func Test_keepMatchingKeys_bad_input(t *testing.T) {
115112 },
116113 }
117114
118- exprFunc , err := keepMatchingKeys [any ](target , "anything" )
115+ pattern := & ottl.StandardStringGetter [any ]{
116+ Getter : func (_ context.Context , _ any ) (any , error ) {
117+ return "anything" , nil
118+ },
119+ }
120+
121+ exprFunc , err := keepMatchingKeys [any ](target , pattern )
122+ assert .NoError (t , err )
123+
124+ _ , err = exprFunc (nil , input )
125+ assert .Error (t , err )
126+ }
127+
128+ func Test_keepMatchingKeys_invalid_pattern (t * testing.T ) {
129+ input := pcommon .NewValueInt (1 )
130+ target := & ottl.StandardPMapGetSetter [any ]{
131+ Getter : func (_ context.Context , tCtx any ) (pcommon.Map , error ) {
132+ if v , ok := tCtx .(pcommon.Map ); ok {
133+ return v , nil
134+ }
135+ return pcommon.Map {}, errors .New ("expected pcommon.Map" )
136+ },
137+ }
138+
139+ pattern := & ottl.StandardStringGetter [any ]{
140+ Getter : func (_ context.Context , _ any ) (any , error ) {
141+ return "*" , nil
142+ },
143+ }
144+
145+ exprFunc , err := keepMatchingKeys [any ](target , pattern )
119146 assert .NoError (t , err )
120147
121148 _ , err = exprFunc (nil , input )
@@ -132,7 +159,13 @@ func Test_keepMatchingKeys_get_nil(t *testing.T) {
132159 },
133160 }
134161
135- exprFunc , err := keepMatchingKeys [any ](target , "anything" )
162+ pattern := & ottl.StandardStringGetter [any ]{
163+ Getter : func (_ context.Context , _ any ) (any , error ) {
164+ return "anything" , nil
165+ },
166+ }
167+
168+ exprFunc , err := keepMatchingKeys [any ](target , pattern )
136169 assert .NoError (t , err )
137170 _ , err = exprFunc (nil , nil )
138171 assert .Error (t , err )
0 commit comments