@@ -16,6 +16,14 @@ import (
16
16
)
17
17
18
18
func Test_GetMapValue_Invalid (t * testing.T ) {
19
+ getSetter := & ottl.StandardGetSetter [any ]{
20
+ Getter : func (_ context.Context , _ any ) (any , error ) {
21
+ return nil , nil
22
+ },
23
+ Setter : func (_ context.Context , _ any , _ any ) error {
24
+ return nil
25
+ },
26
+ }
19
27
tests := []struct {
20
28
name string
21
29
keys []ottl.Key [any ]
@@ -26,42 +34,49 @@ func Test_GetMapValue_Invalid(t *testing.T) {
26
34
keys : []ottl.Key [any ]{
27
35
& TestKey [any ]{
28
36
I : ottltest .Intp (0 ),
37
+ G : getSetter ,
29
38
},
30
39
},
31
- err : fmt .Errorf ("non- string indexing is not supported " ),
40
+ err : fmt .Errorf ("unable to resolve a string index in map: could not resolve key for map/slice, expecting 'string' but got '<nil>' " ),
32
41
},
33
42
{
34
43
name : "index map with int" ,
35
44
keys : []ottl.Key [any ]{
36
45
& TestKey [any ]{
37
46
S : ottltest .Strp ("map" ),
47
+ G : getSetter ,
38
48
},
39
49
& TestKey [any ]{
40
50
I : ottltest .Intp (0 ),
51
+ G : getSetter ,
41
52
},
42
53
},
43
- err : fmt .Errorf ("map must be indexed by a string" ),
54
+ err : fmt .Errorf ("unable to resolve a string index in map: could not resolve key for map/slice, expecting ' string' but got '<nil>' " ),
44
55
},
45
56
{
46
57
name : "index slice with string" ,
47
58
keys : []ottl.Key [any ]{
48
59
& TestKey [any ]{
49
60
S : ottltest .Strp ("slice" ),
61
+ G : getSetter ,
50
62
},
51
63
& TestKey [any ]{
52
64
S : ottltest .Strp ("invalid" ),
65
+ G : getSetter ,
53
66
},
54
67
},
55
- err : fmt .Errorf ("slice must be indexed by an int " ),
68
+ err : fmt .Errorf ("unable to resolve an integer index in slice: could not resolve key for map/slice, expecting 'int64' but got '<nil>' " ),
56
69
},
57
70
{
58
71
name : "index too large" ,
59
72
keys : []ottl.Key [any ]{
60
73
& TestKey [any ]{
61
74
S : ottltest .Strp ("slice" ),
75
+ G : getSetter ,
62
76
},
63
77
& TestKey [any ]{
64
78
I : ottltest .Intp (1 ),
79
+ G : getSetter ,
65
80
},
66
81
},
67
82
err : fmt .Errorf ("index 1 out of bounds" ),
@@ -71,9 +86,11 @@ func Test_GetMapValue_Invalid(t *testing.T) {
71
86
keys : []ottl.Key [any ]{
72
87
& TestKey [any ]{
73
88
S : ottltest .Strp ("slice" ),
89
+ G : getSetter ,
74
90
},
75
91
& TestKey [any ]{
76
92
I : ottltest .Intp (- 1 ),
93
+ G : getSetter ,
77
94
},
78
95
},
79
96
err : fmt .Errorf ("index -1 out of bounds" ),
@@ -83,9 +100,11 @@ func Test_GetMapValue_Invalid(t *testing.T) {
83
100
keys : []ottl.Key [any ]{
84
101
& TestKey [any ]{
85
102
S : ottltest .Strp ("string" ),
103
+ G : getSetter ,
86
104
},
87
105
& TestKey [any ]{
88
106
S : ottltest .Strp ("string" ),
107
+ G : getSetter ,
89
108
},
90
109
},
91
110
err : fmt .Errorf ("type Str does not support string indexing" ),
@@ -102,7 +121,7 @@ func Test_GetMapValue_Invalid(t *testing.T) {
102
121
s .AppendEmpty ()
103
122
104
123
_ , err := GetMapValue [any ](context .Background (), nil , m , tt .keys )
105
- assert .Equal (t , tt .err , err )
124
+ assert .Equal (t , tt .err . Error () , err . Error () )
106
125
})
107
126
}
108
127
}
@@ -129,6 +148,14 @@ func Test_GetMapValue_NilKey(t *testing.T) {
129
148
}
130
149
131
150
func Test_SetMapValue_Invalid (t * testing.T ) {
151
+ getSetter := & ottl.StandardGetSetter [any ]{
152
+ Getter : func (_ context.Context , _ any ) (any , error ) {
153
+ return nil , nil
154
+ },
155
+ Setter : func (_ context.Context , _ any , _ any ) error {
156
+ return nil
157
+ },
158
+ }
132
159
tests := []struct {
133
160
name string
134
161
keys []ottl.Key [any ]
@@ -139,42 +166,49 @@ func Test_SetMapValue_Invalid(t *testing.T) {
139
166
keys : []ottl.Key [any ]{
140
167
& TestKey [any ]{
141
168
I : ottltest .Intp (0 ),
169
+ G : getSetter ,
142
170
},
143
171
},
144
- err : fmt .Errorf ("non- string indexing is not supported " ),
172
+ err : fmt .Errorf ("unable to resolve a string index in map: could not resolve key for map/slice, expecting 'string' but got '<nil>' " ),
145
173
},
146
174
{
147
175
name : "index map with int" ,
148
176
keys : []ottl.Key [any ]{
149
177
& TestKey [any ]{
150
178
S : ottltest .Strp ("map" ),
179
+ G : getSetter ,
151
180
},
152
181
& TestKey [any ]{
153
182
I : ottltest .Intp (0 ),
183
+ G : getSetter ,
154
184
},
155
185
},
156
- err : fmt .Errorf ("map must be indexed by a string" ),
186
+ err : fmt .Errorf ("unable to resolve a string index in map: could not resolve key for map/slice, expecting ' string' but got '<nil>' " ),
157
187
},
158
188
{
159
189
name : "index slice with string" ,
160
190
keys : []ottl.Key [any ]{
161
191
& TestKey [any ]{
162
192
S : ottltest .Strp ("slice" ),
193
+ G : getSetter ,
163
194
},
164
195
& TestKey [any ]{
165
196
S : ottltest .Strp ("map" ),
197
+ G : getSetter ,
166
198
},
167
199
},
168
- err : fmt .Errorf ("slice must be indexed by an int " ),
200
+ err : fmt .Errorf ("unable to resolve an integer index in slice: could not resolve key for map/slice, expecting 'int64' but got '<nil>' " ),
169
201
},
170
202
{
171
203
name : "slice index too large" ,
172
204
keys : []ottl.Key [any ]{
173
205
& TestKey [any ]{
174
206
S : ottltest .Strp ("slice" ),
207
+ G : getSetter ,
175
208
},
176
209
& TestKey [any ]{
177
210
I : ottltest .Intp (1 ),
211
+ G : getSetter ,
178
212
},
179
213
},
180
214
err : fmt .Errorf ("index 1 out of bounds" ),
@@ -184,9 +218,11 @@ func Test_SetMapValue_Invalid(t *testing.T) {
184
218
keys : []ottl.Key [any ]{
185
219
& TestKey [any ]{
186
220
S : ottltest .Strp ("slice" ),
221
+ G : getSetter ,
187
222
},
188
223
& TestKey [any ]{
189
224
I : ottltest .Intp (- 1 ),
225
+ G : getSetter ,
190
226
},
191
227
},
192
228
err : fmt .Errorf ("index -1 out of bounds" ),
@@ -196,9 +232,11 @@ func Test_SetMapValue_Invalid(t *testing.T) {
196
232
keys : []ottl.Key [any ]{
197
233
& TestKey [any ]{
198
234
S : ottltest .Strp ("string" ),
235
+ G : getSetter ,
199
236
},
200
237
& TestKey [any ]{
201
238
S : ottltest .Strp ("string" ),
239
+ G : getSetter ,
202
240
},
203
241
},
204
242
err : fmt .Errorf ("type Str does not support string indexing" ),
@@ -215,7 +253,7 @@ func Test_SetMapValue_Invalid(t *testing.T) {
215
253
s .AppendEmpty ()
216
254
217
255
err := SetMapValue [any ](context .Background (), nil , m , tt .keys , "value" )
218
- assert .Equal (t , tt .err , err )
256
+ assert .Equal (t , tt .err . Error () , err . Error () )
219
257
})
220
258
}
221
259
}
0 commit comments