Orange-OpenSource / hurl

Hurl, run and test HTTP requests with plain text.
https://hurl.dev
Apache License 2.0
13.11k stars 491 forks source link

Math operations #1269

Open tommyiswhoiam opened 1 year ago

tommyiswhoiam commented 1 year ago

Problem to solve

The problem is that the hurl library does not currently support math operations in the Assets section of a test case. This makes it difficult for users to perform calculations on captured data and use it to make assertions in their tests.

Proposal

The proposal is to add support for basic math operations (e.g. addition, subtraction, multiplication, division) in the Assets section of a test case. This will allow users to perform calculations on captured data and use it to make assertions in their tests.

For example, the following code will be possible:

[Captures]
balance_before: jsonpath "$.result.balance"

# ...

[Asserts]
jsonpath "$.result.balance" == {{balance_before}} + 100

Additional context and resources

This feature would be useful for users who need to perform calculations on captured data and make assertions based on the results. It is a common use case in API testing, where users need to perform calculations on returned data to verify that it meets certain conditions.

There are other API testing tools that already support this feature, such as Postman and SoapUI. Adding this feature to the hurl library will make it more competitive with these tools.

Tasks to complete

fabricereix commented 1 year ago

Hi @tommyiswhoiam That would indeed be a good feature to have.

Relating to the implementation, we could maybe fit it in the existing format with filters. We could also apply them to predicate value.

Relating to operators, we have already used them for predicates (eg == for equals). Similarly for filters + for add.

fabricereix commented 1 year ago

The first step would be therefore to try to apply filters to predicate value. That would be useful to create literals. eg. cookie "SESSION_ID[Expired]" == "2023-02-13T12:37:53+00:00" toDateIso8601

xu4wang commented 1 year ago

I open #1872 a few hours ago.

Looks like this is the answer.. Looking forward for this new feature.

DenuxPlays commented 6 months ago

Any updates?