Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
belimawr committed Nov 25, 2021
1 parent a83565c commit c469e56
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions libbeat/processors/actions/decode_json_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,27 @@ func TestOverwriteMetadata(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestAddErrorToEventOnUnmarshalError(t *testing.T) {
testConfig := common.MustNewConfigFrom(map[string]interface{}{
"fields": "message",
"add_error_key": true,
})

input := common.MapStr{
"message": "Broken JSON [[",
}

actual := getActualValue(t, testConfig, input)

errObj, ok := actual["error"].(common.MapStr)
require.True(t, ok, "'error' field not present or of invalid type")
require.NotNil(t, actual["error"])

assert.Equal(t, "message", errObj["field"])
assert.NotNil(t, errObj["data"])
assert.NotNil(t, errObj["message"])
}

func getActualValue(t *testing.T, config *common.Config, input common.MapStr) common.MapStr {
log := logp.NewLogger("decode_json_fields_test")

Expand Down

0 comments on commit c469e56

Please sign in to comment.