@@ -273,12 +273,28 @@ func TestFromMapstrSliceCommonTime(t *testing.T) {
273
273
assert .Equal (t , want , inputMap )
274
274
}
275
275
276
+ type structWithTextMarshaler struct {
277
+ Value string `json:"value"`
278
+ }
279
+
280
+ func (s * structWithTextMarshaler ) MarshalText () ([]byte , error ) {
281
+ return []byte ("marshalled:" + s .Value ), nil
282
+ }
283
+
276
284
func TestFromMapstrWithNestedData (t * testing.T ) {
277
285
input := mapstr.M {
278
286
"any_array" : [3 ]any {1 , "string" , 3 },
279
287
"any_slice" : []any {5.1 , 6.2 },
280
288
"bool_array" : [2 ]bool {true , false },
281
289
"bool_slice" : []bool {false , true },
290
+ "struct" : struct {
291
+ Value string `json:"value"`
292
+ }{
293
+ Value : "string" ,
294
+ },
295
+ "struct_with_text_marshaler" : & structWithTextMarshaler {
296
+ Value : "string" ,
297
+ },
282
298
"inner" : []mapstr.M {
283
299
{
284
300
"inner_int" : 42 ,
@@ -287,6 +303,14 @@ func TestFromMapstrWithNestedData(t *testing.T) {
287
303
{"string" : "string" },
288
304
{"number" : 12.3 },
289
305
},
306
+ "inner_struct" : struct {
307
+ Value string `json:"value"`
308
+ }{
309
+ Value : "string" ,
310
+ },
311
+ "inner_struct_with_text_marshaler" : & structWithTextMarshaler {
312
+ Value : "string" ,
313
+ },
290
314
},
291
315
{
292
316
"inner_int" : 43 ,
@@ -306,6 +330,10 @@ func TestFromMapstrWithNestedData(t *testing.T) {
306
330
"any_slice" : []any {5.1 , 6.2 },
307
331
"bool_array" : []any {true , false },
308
332
"bool_slice" : []any {false , true },
333
+ "struct" : map [string ]any {
334
+ "value" : "string" ,
335
+ },
336
+ "struct_with_text_marshaler" : "marshalled:string" ,
309
337
"inner" : []any {
310
338
map [string ]any {
311
339
"inner_int" : 42 ,
@@ -314,6 +342,10 @@ func TestFromMapstrWithNestedData(t *testing.T) {
314
342
map [string ]any {"string" : "string" },
315
343
map [string ]any {"number" : 12.3 },
316
344
},
345
+ "inner_struct" : map [string ]any {
346
+ "value" : "string" ,
347
+ },
348
+ "inner_struct_with_text_marshaler" : "marshalled:string" ,
317
349
},
318
350
map [string ]any {
319
351
"inner_int" : 43 ,
@@ -363,24 +395,12 @@ func TestToMapstr(t *testing.T) {
363
395
assert .Equal (t , want , got )
364
396
}
365
397
366
- type unknown struct {
367
- Value int `json:"value"`
368
- }
369
-
370
398
func TestUnknownType (t * testing.T ) {
371
399
inputMap := mapstr.M {
372
- "unknown" : unknown {42 },
373
- "nested" : mapstr.M {
374
- "unknown" : unknown {43 },
375
- },
376
400
"unknown_map" : map [string ]int {"key" : 42 },
377
401
}
378
402
379
403
expected := mapstr.M {
380
- "unknown" : "unknown type: otelmap.unknown" ,
381
- "nested" : map [string ]any {
382
- "unknown" : "unknown type: otelmap.unknown" ,
383
- },
384
404
"unknown_map" : "unknown type: map[string]int" ,
385
405
}
386
406
0 commit comments