Skip to content

Commit

Permalink
test interface slices/maps and struct maps
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed May 7, 2024
1 parent 3259b71 commit e0cd368
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bridges/otellogrus/hook_test.go
Expand Up @@ -319,20 +319,44 @@ func TestConvertFields(t *testing.T) {
),
},
},
{
name: "with an interface slice",
fields: logrus.Fields{"hello": []interface{}{"foo", 42}},
wantKeyValue: []log.KeyValue{
log.Slice("hello",
log.StringValue("foo"),
log.Int64Value(42),
),
},
},
{
name: "with a map",
fields: logrus.Fields{"hello": map[string]int{"answer": 42}},
wantKeyValue: []log.KeyValue{
log.Map("hello", log.Int("answer", 42)),
},
},
{
name: "with an interface map",
fields: logrus.Fields{"hello": map[interface{}]interface{}{1: "question", "answer": 42}},
wantKeyValue: []log.KeyValue{
log.Map("hello", log.String("1", "question"), log.Int("answer", 42)),
},
},
{
name: "with a nested map",
fields: logrus.Fields{"hello": map[string]map[string]int{"sublevel": {"answer": 42}}},
wantKeyValue: []log.KeyValue{
log.Map("hello", log.Map("sublevel", log.Int("answer", 42))),
},
},
{
name: "with a struct map",
fields: logrus.Fields{"hello": map[struct{ name string }]string{{name: "hello"}: "world"}},
wantKeyValue: []log.KeyValue{
log.Map("hello", log.String("{name:hello}", "world")),
},
},
{
name: "with a pointer to struct",
fields: logrus.Fields{"hello": &struct{ Name string }{Name: "foobar"}},
Expand Down

0 comments on commit e0cd368

Please sign in to comment.