forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recursive split to httpjson (elastic#21214)
(cherry picked from commit 43ca900)
- Loading branch information
Showing
2 changed files
with
107 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package httpjson | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSplitEventsBy(t *testing.T) { | ||
event := map[string]interface{}{ | ||
"this": "is kept", | ||
"alerts": []interface{}{ | ||
map[string]interface{}{ | ||
"this_is": "also kept", | ||
"entities": []interface{}{ | ||
map[string]interface{}{ | ||
"something": "something", | ||
}, | ||
map[string]interface{}{ | ||
"else": "else", | ||
}, | ||
}, | ||
}, | ||
map[string]interface{}{ | ||
"this_is": "also kept 2", | ||
"entities": []interface{}{ | ||
map[string]interface{}{ | ||
"something": "something 2", | ||
}, | ||
map[string]interface{}{ | ||
"else": "else 2", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
expectedEvents := []map[string]interface{}{ | ||
{ | ||
"this": "is kept", | ||
"alerts": map[string]interface{}{ | ||
"this_is": "also kept", | ||
"entities": map[string]interface{}{ | ||
"something": "something", | ||
}, | ||
}, | ||
}, | ||
{ | ||
"this": "is kept", | ||
"alerts": map[string]interface{}{ | ||
"this_is": "also kept", | ||
"entities": map[string]interface{}{ | ||
"else": "else", | ||
}, | ||
}, | ||
}, | ||
{ | ||
"this": "is kept", | ||
"alerts": map[string]interface{}{ | ||
"this_is": "also kept 2", | ||
"entities": map[string]interface{}{ | ||
"something": "something 2", | ||
}, | ||
}, | ||
}, | ||
{ | ||
"this": "is kept", | ||
"alerts": map[string]interface{}{ | ||
"this_is": "also kept 2", | ||
"entities": map[string]interface{}{ | ||
"else": "else 2", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const key = "alerts..entities" | ||
|
||
got := splitEvent(key, event) | ||
|
||
assert.Equal(t, expectedEvents, got) | ||
} |