✨ Implement full support for nested fields in Meta and Entry marshalling
This commit completes the implementation of nested field support.
- :
- now correctly handles and by recursively flattening them into format.
- Introduced for recursive map marshalling.
- Refactored for cleaner buffer writing.
- : Added comprehensive test cases for nested JSON, nested maps, double-nested maps, and nested keys within JSON to ensure correct marshalling and unmarshalling.
- : Updated tests to reflect the new nil handling and removed redundant JSON object test.
This allows for more flexible and structured data representation within log entries.
This commit is contained in:
parent
c4e864afa5
commit
4fc1c623a0
3 changed files with 90 additions and 6 deletions
|
|
@ -61,6 +61,42 @@ func TestEntryMarshal(t *testing.T) {
|
|||
[]string{"@age 41", "@cool true", "@name Jim"},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"nested-json",
|
||||
"Title N",
|
||||
when,
|
||||
[]Meta{{"me", json.RawMessage(`{"age": 43, "cool": true}`)}},
|
||||
"@begin " + whens + " - Title N",
|
||||
[]string{"@me:age 43", "@me:cool true"},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"nested-map",
|
||||
"Title M",
|
||||
when,
|
||||
[]Meta{{"me", map[string]any{"age": 43, "cool": true}}},
|
||||
"@begin " + whens + " - Title M",
|
||||
[]string{"@me:age 43", "@me:cool true"},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"double-nested-map",
|
||||
"Title DM",
|
||||
when,
|
||||
[]Meta{{"me", map[string]any{"age": 43, "name": map[string]any{"first": "Dan", "last": "Jones"}}}},
|
||||
"@begin " + whens + " - Title DM",
|
||||
[]string{"@me:age 43", "@me:name:first Dan", "@me:name:last Jones"},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"nested-keys-in-json",
|
||||
"Title NKJ",
|
||||
when,
|
||||
[]Meta{{"me", json.RawMessage(`{"name:first": "Dan", "name:last": "Jones"}`)}},
|
||||
"@begin " + whens + " - Title NKJ",
|
||||
[]string{"@me:name:first Dan", "@me:name:last Jones"},
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
@ -219,6 +255,7 @@ func TestEntryJsonMarshal(t *testing.T) {
|
|||
{"json-field", "A Title", when, []Meta{{"json", json.RawMessage(`{"age": 41, "cool": true, "name": "Jim"}`)}}, `{"title":"A Title","date":"` + whens + `","age":41,"cool": true, "name": "Jim"}`, nil},
|
||||
{"nested-field", "A Title", when, []Meta{{"obj:foo", "bar"}, {"obj:title", "Sub-title"}}, `{"title":"A Title","date":"` + whens + `","obj":{"foo":"bar","title":"Sub-title"}}`, nil},
|
||||
{"double-nested-field", "A Title", when, []Meta{{"obj:foo", "bar"}, {"obj:me:name", "Dan"}, {"obj:me:age", 27}}, `{"title":"A Title","date":"` + whens + `","obj":{"foo":"bar","me":{"name":"Dan","age":27}}}`, nil},
|
||||
{"nested-plus-json", "A Title", when, []Meta{{"obj:foo", "bar"}, {"obj:me", json.RawMessage(`{"name":"Dan","age":27}`)}}, `{"title":"A Title","date":"` + whens + `","obj":{"foo":"bar","me":{"name":"Dan","age":27}}}`, nil},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue