feat(unit tests): add expected_event_count field to test outputs#25186
feat(unit tests): add expected_event_count field to test outputs#25186
expected_event_count field to test outputs#25186Conversation
4e0e025 to
25de938
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25de9386cb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Add an optional `expected_event_count` field to the `TestOutput` config struct, allowing users to assert on the number of events emitted by a transform in unit tests. The count check is independent of conditions and is verified first. - Reject `expected_event_count: 0` with conditions at build time - Error on conflicting counts when multiple outputs share extract_from - Allow `expected_event_count: 0` to suppress the "no events received" error when zero events are genuinely expected Closes #20278 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
25de938 to
c0e636c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0e636c799
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
A config could bypass the zero-count/conditions validation by splitting expected_event_count: 0 and conditions across two output entries sharing the same extract_from. After merge the combined entry had count 0 with non-empty conditions, causing conditions to pass vacuously against zero events. Add a post-merge check to catch this. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| transforms: | ||
| foo: | ||
| inputs: | ||
| - ignored | ||
| type: remap | ||
| source: | | ||
| . = [{"message": "one"}, {"message": "two"}, {"message": "three"}] | ||
| tests: | ||
| - name: wrong event count | ||
| inputs: | ||
| - insert_at: foo | ||
| value: doesnt matter | ||
| outputs: | ||
| - extract_from: foo | ||
| expected_event_count: 2 | ||
| conditions: | ||
| - type: vrl | ||
| source: | | ||
| assert!(exists(.message), "message field must exist") |
There was a problem hiding this comment.
nit: this is too far indented. Doesn't matter because of how indoc works
| test_outputs: &[TestOutput], | ||
| ) -> Result<IndexMap<Vec<OutputId>, Vec<Vec<Condition>>>, Vec<String>> { | ||
| let mut outputs: IndexMap<Vec<OutputId>, Vec<Vec<Condition>>> = IndexMap::new(); | ||
| ) -> Result<IndexMap<Vec<OutputId>, (Option<usize>, Vec<Vec<Condition>>)>, Vec<String>> { |
There was a problem hiding this comment.
This type is too big, we should probably use a struct here
Summary
expected_event_countfield to theTestOutputconfig struct, allowing users to assert on the number of events emitted by a transform in unit tests.remap), where previously there was no way to verify the event count.This is a low hanging since it was requested multiple times across various channels and it's easy to implement.
Vector configuration
How did you test this PR?
Added two unit tests in
src/config/unit_test/tests.rs:expected_event_count_correct- verifies a matching count passesexpected_event_count_wrong- verifies a mismatched count produces a clear error messageAlso ran
make check-clippy,make check-fmt, andmake check-generated-docslocally.Change Type
Is this a breaking change?
Does this PR include user facing changes?
no-changeloglabel to this PR.References
🤖 Generated with Claude Code