Run entry when it matches some condition?
Problem to solve
Our application supports MySQL and OpenLDAP backends, there're few differences between them, we'd like to run certain hurl entries when it's using X backend. I didn't find condition support in hurl document.
Proposal
Any plan to support such conditions in hurl so that we don't need to handle it with shell script?
Like Ansible, use when:: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_conditionals.html#basic-conditionals-with-when
tasks:
- name: Shut down Debian flavored systems
ansible.builtin.command: /sbin/shutdown -t now
when: ansible_facts['os_family'] == "Debian"
And hurl:
POST {{server}}/domain/abc.io
WHEN: my_variable=my_value
HTTP 200
[Asserts]
...
Hi @jcamiel,
Thanks for the reply.
- How do i define when it should be true/false? For example:
skip: my_var=my_value? - What if i need to skip for more cases and execute it for less cases? It will require more
skip:checks.
A when: like Ansible might be a lot easier. :)
FYI: An "if" was asked twice when I did my Hurl talk
Unfortunately I'm trying to do a dynamic skip and I depend on knowing if an entry exists.
Then I perform a search (GET) and do a capture.
And then it would execute an insertion (POST) if the GET does not return a result.
However, capture only supports query and filter, and none of the filters have the ability to return true or false.
The solution in my opinion would be to easily add a toBool filter similar to toInt that allows you to convert non-zero values to true and zero to false.
Or the more precise solution would be for captures to support the predicate generating a boolean variable that can be used in skip.
With dynamic repeat and skip working correctly I don't see any need for if/else and for loops
Hi @marcodpt
We can implement a toBool filter (should we decide how we compute "trusly" and "falsy"), but I wondering if we shouldn't try to use existing notion of predicates == , !=, contains etc...
skip only supports for the moment literal value or expression like {{skip}} but we could imagine something like:
GET https://foo.com/search?q=toto
HTTP 200
[Captures]
name: jsonpath "$.results"
# Only create if we have no result
POST https://foo.com/create
[Options]
skip: {{ results isEmpty }}
HTTP 200
I think we get the use case, we just need to find something that is not completely alien from the current model. skip is already something a little hacky, it's the only option that can be set on [Options]section and not on CLI. We really want to make something coherant, useful but not too complicated...
Hi @jcamiel,
Thank you very much for your comment.
If captures supports predicates, we have assertions and captures with an absolutely identical syntax.
The advantage is that it is possible to generate Boolean expressions to use in skip.
And another advantage is that it simplifies the syntax of .hurl files as captures and assertions will be absolutely identical.
This allows me to do this:
GET https://foo.com/search?q=toto
HTTP 200
[Captures]
name: jsonpath "$.results" isEmpty
# Only create if we have no result
POST https://foo.com/create
[Options]
skip: {{results}}
HTTP 200
Note that in this case captures and assertions have identical syntax and that only the isEmpty predicate was moved from your example
The toBool filter proposal was just a hack if it was not feasible to change the parser syntax.
I want to make it very clear that I am extremely grateful for your work and these are just opinions to improve the hurl even further.
Take as much time as necessary and prioritize the stability and correctness of the hurl.
Can we support var == value syntax in skip:? Just like Ansible when:.
for example:
skip: {{ my_var }} == "abc"
also looking for this options to skip a test or set proxy for a test when its run in CI vs locally