How to make "negative" unit tests? #2490
-
In our streams we would like to create some unit tests to verify that when the stream process a broken message, the stream handles the error correctly (logging, eventual post-processing, etc..). If we write a unit test with a broken message as input, the stream correctly handles the error but the test fails with the "wrong batch count, expected 1, got 0" message. Is there any way to test this? Sample configuration as reference:
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @alessandro-gomma 👋 One approach is to write a test which expects 0 batches: pipeline:
processors:
- mapping: |
root = throw("kaboom!")
- catch:
- mapping: root = if errored() { deleted() }
tests:
- name: test deleted
target_processors: '/pipeline/processors'
input_batch:
- content: 'foobar'
output_batches: [] Alternatively, depending on what your pipeline does and where you place that pipeline:
processors:
- mapping: |
root = throw("kaboom!")
- catch:
- label: mockme
mapping: root = if errored() { deleted() }
tests:
- name: test deleted
target_processors: '/pipeline/processors'
mocks:
mockme:
mapping: root = "ERROR"
input_batch:
- content: 'foobar'
output_batches:
-
- content_equals: ERROR |
Beta Was this translation helpful? Give feedback.
Hey @alessandro-gomma 👋 One approach is to write a test which expects 0 batches:
Alternatively, depending on what your pipeline does and where you place that
mapping
processor which contains thedeleted()
call, you could mock it such that it returns some dummy data instead. Something like this: