connect
connect copied to clipboard
Ability to mock the now function for testing
Benthos unit testing is great and I've had good success with it. Now I have a use case however where I embed the current time in the JSON output generated in the pipeline. When unit testing this becomes a problem because when you do a json_equals
testing operation there is no easy way to compare to a fixed time.
It would be really useful if one can override the now()
function in a test in order to emit a hardcoded time.
Just incase anyone finds this like myself, there are also json_contains
and file_json_contains
that can be used in some scenarios to workaround this. For example, if your processor has something like root.Timestamp = now().ts_tz("UTC")
you can use the json_contains
methods and simply omit Timestamp
in your expected output.