Vector Unit Testing - Cant send or parse array/json elements directly #12086
-
Config yaml:
Test file:
Command: Error:
But when i run the vector file alone with below message input, it does parse it. but how can i test the use case by just sending message json alone.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @satscreate ! The issue here is that you are passing in a raw string where the actual topology will parse the string as JSON due to setting As you note, there is a bug prohibiting arrays to be used as fields that is being tracked by #9386 You can, however, flatten out the object keys like this: - name: validate-result-log-block
inputs:
- insert_at: filter-empty
type: log
log_fields:
host: "0.0"
source: test
id: testid
recorded: date
message: some message
actors[0].type: user
actors[0].name: somename
actors[0].id: someid
resources[0].id: ""
resources[0].type: ""
resources[0].name: ""
resources[0].session: test
result.status: test
result.message: somemessage
outputs:
- extract_from: parse-result-log
conditions:
- type: vrl
source: |-
assert!(.host == "0.0")
assert!(.session == "test") This will result in the JSON you had (I made some slight tweaks to the fields to get the tests passing: adding a |
Beta Was this translation helpful? Give feedback.
Hi @satscreate !
The issue here is that you are passing in a raw string where the actual topology will parse the string as JSON due to setting
decoding.codec = "json"
on thestdin
source.As you note, there is a bug prohibiting arrays to be used as fields that is being tracked by #9386
You can, however, flatten out the object keys like this: