connect icon indicating copy to clipboard operation
connect copied to clipboard

Ability to mock the now function for testing

Open hannesdejager opened this issue 2 years ago • 1 comments

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.

hannesdejager avatar Apr 20 '22 19:04 hannesdejager

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.

adam-knights avatar Feb 07 '24 11:02 adam-knights