Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple possible status assertions #2035

Open
smokedlinq opened this issue Oct 11, 2023 · 13 comments
Open

Support for multiple possible status assertions #2035

smokedlinq opened this issue Oct 11, 2023 · 13 comments
Labels
enhancement New feature or request topic: predicates
Milestone

Comments

@smokedlinq
Copy link

Problem to solve

Support asserts for status that could return one or more possible status codes that are valid, e.g. 200, 201, 202, 204, 409. The range status check doesn't work when you want to use a complex set like 200, 424, and 503.

Proposal

Option 1 - Add a toString filter so that a matches predicate can be used: status toString matches "^(200|424|503)$"

Option 2 - Add support for a predicate that finds one or more values: status <some_predicate_expression> [200,424,503]; some_predicate_expression could be isOneOf, includedIn, isAnyOf, etc.

Option 3 - Add support for an array of values to write the includes like: [200, 424, 503] has status

Additional context and resources

We have an API endpoint we want to test that could return a different response depending on the state of the system. These are valid responses but we don't want to fail the test as long as it is one of the expected statuses.

@smokedlinq smokedlinq added the enhancement New feature or request label Oct 11, 2023
@jcamiel
Copy link
Collaborator

jcamiel commented Oct 11, 2023

Interesting problem! We can see how to adapt the current syntax to deal with it.

@fabricereix
Copy link
Collaborator

Hi @smokedlinq
I like option 2, we could have predicates that take several values

status isOneOf 200 204

@jcamiel
Copy link
Collaborator

jcamiel commented Oct 11, 2023

Another possibility 😊: use or with predicates values. It can works with existing predicates:

GET https://foo.com
HTTP 200
[Asserts]
jsonpath "$.name" == "toto" or "tata"
headers "Content-type" contains "text" or "json" or "csv"
status == 204 or 205 or 206

Remind me also of #347 where we discussed about each, any, none. Would be cool if the two syntaxes play nicely together:

jsonpath "$.values" any == 3
jsonpath "$.values" any > 0 
jsonpath "$.values" any matches "value.*"
jsonpath "$.values" none == 3
jsonpath "$.values" none > 0 
jsonpath "$.values" none matches "value.*"

@fabricereix
Copy link
Collaborator

Another possibility:
the or could even be applied to the predicate itself
This is less readable but more flexible/powerful

status == 200 or == 300   
status < 300 or == 500

@smokedlinq
Copy link
Author

smokedlinq commented Oct 12, 2023

How about an in predicate?

status in 200 424 503
jsonpath "$.status" in "Healthy" "Degraded" "Unhealthy"

@jcamiel
Copy link
Collaborator

jcamiel commented Oct 12, 2023

in is cool, the only thing that make me tickle is that all our current predicates are at the 3rd person startsWith, endsWith, contains, includes, matches, exists, isBoolean, isCollection, isDate, isEmpty,isFloat, isInteger, isString... I can also convince me that in is an operator like >, < etc....

@fabricereix
Copy link
Collaborator

in seems indeed familiar.
I would expect a collection of values after it (in fact it is the same for isOneOf)

For example, reducing the example to one value

jsonpath "$.status" in "Healthy" 

it can be ambiguous. Do we have a collection of one value or the string itself is a collection (like in Python)?

@jcamiel
Copy link
Collaborator

jcamiel commented Oct 13, 2023

Go for in!

@lepapareil
Copy link
Collaborator

lepapareil commented Oct 13, 2023

I agree that in is familiar, but it seems to me that isOneOf is more explicit and therefore more readable by all types of users (non-developers), and above all it's a verb like all Hurl's predicates.

@fabricereix
Copy link
Collaborator

Devops that use Python should be happy with in

@lepapareil
Copy link
Collaborator

lepapareil commented Oct 13, 2023

This brings us back to the issue of naming the jsonSchema validation predicate: do we only use verbs or not ? 🤔

@jcamiel jcamiel added this to the 4.2.0 milestone Oct 17, 2023
@jcamiel jcamiel modified the milestones: 4.2.0, 4.3.0 Jan 10, 2024
@jcamiel jcamiel modified the milestones: 4.3.0, 5.0.0 Apr 17, 2024
@smacktoid
Copy link

This feature would be really nice. The scenario I hit recently was where I had some requests which will set up data for later tests.

It would be nice if these setup requests would tolerate the data being in place already, in which case my API will return a 409 status.

So I’d have set the assertion to accept 201 or 409.

@jcamiel jcamiel modified the milestones: 5.0.0, 5.1.0 Aug 28, 2024
@jcamiel jcamiel modified the milestones: 6.0.0, 6.1.0 Dec 3, 2024
@ossie-git
Copy link

Somewhat related to this issue, I was wondering if there is any direction of embedding something like Lua to allow for custom filters, asserts and captures. I was thinking of opening it as a separate issue but it appears that this is one example of a use case. It would also open up the door for a lot more customization. I don't know Rust but I have seen praise for the mlua crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request topic: predicates
Projects
None yet
Development

No branches or pull requests

6 participants