From 502f48d1b8da5f887a6639540f2574d70c15b312 Mon Sep 17 00:00:00 2001 From: dmathieu <42@dmathieu.com> Date: Tue, 7 May 2024 09:33:22 +0200 Subject: [PATCH] test interface slices/maps and struct maps --- bridges/otellogrus/hook_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bridges/otellogrus/hook_test.go b/bridges/otellogrus/hook_test.go index 7991764ab02..3ca34c02265 100644 --- a/bridges/otellogrus/hook_test.go +++ b/bridges/otellogrus/hook_test.go @@ -319,6 +319,16 @@ 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}}, @@ -326,6 +336,13 @@ func TestConvertFields(t *testing.T) { 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}}}, @@ -333,6 +350,13 @@ func TestConvertFields(t *testing.T) { 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"}},