atkrad / wait4x

Wait4X allows you to wait for a port or a service to enter the requested state.
https://wait4x.dev
Apache License 2.0
266 stars 18 forks source link

--expect-body-json comparison with value #203

Open lzecca78 opened 11 months ago

lzecca78 commented 11 months ago

Hi, i am using wait4x in the pipeline using the HTTP provider in order to compare a specific body JSON key with a specific value. AFAIK, also looking at the gjson doc, this seems not possible. For example a body with


{"version": 1234} 

cannot be done afaik with --expect-body-json with something like:

wait4x http https://ifconfig.co/json --expect-body-json "version==1234" or something similar.

mortymacs commented 11 months ago

Hi,

Unfortunately, at the moment, we and gjson only check the existence of keys therefore you can use --expect-body-regex instead:

$ wait4x http https://ifconfig.co/json --expect-body-regex '"version": "1234"'

The "condition" only works in the array based on the gjson documentation https://github.com/tidwall/gjson

@atkrad suggested to use https://github.com/antonmedv/expr to handle complex expressions. Maybe in the future, we'll support it. @lzecca78 you can send a PR if you would like to contribute.

If you have any ideas, we would be happy to hear them to fix the issue fundamentally.