Skip to content

feat(unit tests): add expected_event_count field to test outputs#25186

Open
pront wants to merge 4 commits intomasterfrom
pavlos/expected-event-count-unit-tests
Open

feat(unit tests): add expected_event_count field to test outputs#25186
pront wants to merge 4 commits intomasterfrom
pavlos/expected-event-count-unit-tests

Conversation

@pront
Copy link
Copy Markdown
Member

@pront pront commented Apr 14, 2026

Summary

  • Adds 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.
  • Useful for transforms that emit multiple events (e.g., remap), where previously there was no way to verify the event count.
  • Fully backwards-compatible: omitting the field skips the check entirely.

This is a low hanging since it was requested multiple times across various channels and it's easy to implement.

Vector configuration

tests:
  - name: split produces three events
    inputs:
      - insert_at: my_transform
        value: "one,two,three"
    outputs:
      - extract_from: my_transform
        expected_event_count: 3
        conditions:
          - type: vrl
            source: |
              assert!(exists(.message), "message field must exist")

How did you test this PR?

Added two unit tests in src/config/unit_test/tests.rs:

  1. expected_event_count_correct - verifies a matching count passes
  2. expected_event_count_wrong - verifies a mismatched count produces a clear error message

Also ran make check-clippy, make check-fmt, and make check-generated-docs locally.

Change Type

  • Bug fix
  • New feature
  • Dependencies
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

🤖 Generated with Claude Code

@pront pront force-pushed the pavlos/expected-event-count-unit-tests branch from 4e0e025 to 25de938 Compare April 14, 2026 15:00
@pront pront marked this pull request as ready for review April 14, 2026 15:00
@pront pront requested a review from a team as a code owner April 14, 2026 15:00
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/config/unit_test/unit_test_components.rs
Comment thread src/config/unit_test/mod.rs
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>
@pront pront force-pushed the pavlos/expected-event-count-unit-tests branch from 25de938 to c0e636c Compare April 14, 2026 15:39
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/config/unit_test/mod.rs
pront and others added 2 commits April 14, 2026 11:54
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>
Copy link
Copy Markdown
Contributor

@thomasqueirozb thomasqueirozb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

Comment on lines +1342 to +1360
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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type is too big, we should probably use a struct here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: allow to test the number of events emitted by a transform

2 participants