Now Reading
Asserting Hurl 4.0.0

Asserting Hurl 4.0.0

2023-06-30 12:44:15

Jun. 30, 2023

The Hurl crew is pleased to announce Hurl 4.0.0 Partying Face !

Hurl is a command line software powered by curl, that runs HTTP requests outlined
in a easy plain textual content format:

GET https://instance.org/api/assessments/4567

HTTP 200

header "x-foo" accommodates "bar"
certificates "Expire-Date" daysAfterNow > 15
jsonpath "$.standing" == "RUNNING"    
jsonpath "$.assessments" depend == 25      
jsonpath "$.id" matches /d{4}/     

What’s new on this launch:

We’ve improved Hurl HTML report. The HTML report is pure HTML, with none JavaScript and with inlined CSS, so it’s must be
straightforward to combine in your favourite CI/CD resolution (like GitLab CI/CD or GitHub Actions for example). Now, every run produces:

  • a waterfall timeline: every request/response is displayed on a good looking graph, with quick access to response timings (DNS,
    TCP handshake, time to first byte and many others…). These timings are offered by libcurl and you’ll find a proof of every
    indicator in the documentation
  • a run log with request and response headers, certificates data and many others…
  • a syntax coloured supply file with inline errors
Requests timeline

The timings used to assemble the requests timeline are additionally uncovered via --json option. --json offers you a structured
view of a Hurl run with errors, asserts, certificates, captures, cookies and so timings. You may even use it to provide your individual report!

Once you see it, you can’t unsee it

What’s fascinating with wealthy visualisation is it could possibly reveal hidden or not apparent issues. For example, you possibly can have this
type of gaps on some runs:

After evaluation, the hole between requests on this pattern take a look at is brought on by an enormous numbers of assertions on the HTTP response. We now have, as of Hurl 4.0.0, a naive
method of asserts computation: every asserts of the identical response is unbiased, and we parse and recompute each assert from scratch.
Till we see these edge circumstances, we had been very happy with Hurl pace (because of the mixture of libcurl and
Rust). Now, we all know that we now have to enhance assert efficiency for the subsequent launch Sad Pensive Face Emoji !

Once you’ve error in some take a look at, the evaluation will be troublesome since you don’t have quite a lot of data aside of the anticipated
values:

$ hurl --test take a look at.hurl
take a look at.hurl: Operating [1/1]
error: Assert failure
  --> take a look at.hurl:4:0
   |
 4 | header "Management-Safety-Coverage" accommodates "default-src 'self'" 
   |   precise:   none
   |   anticipated: accommodates string <default-src 'self'>
   |

take a look at.hurl: Failure (1 request(s) in 128 ms)
--------------------------------------------------------------------------------
Executed information:  1
Succeeded information: 0 (0.0%)
Failed information:    1 (100.0%)
Length:        130 ms

With the brand new --error-format option, you possibly can choose in for an extended error description. On this mode, the response header and the response
physique are mechanically logged:

$ hurl --error-format lengthy --test take a look at.hurl
take a look at.hurl: Operating [1/1]
HTTP/2 200
date: Thu, 29 Jun 2023 16:06:58 GMT
content-type: textual content/html
content-length: 58941
last-modified: Thu, 29 Jun 2023 14:37:22 GMT
etag: "649d9722-e63d"
strict-transport-security: max-age=31536000; includeSubDomains
content-security-policy: default-src 'self'; script-src 'self' 'unsafe-eval' 'wasm-unsafe-eval'
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
accept-ranges: bytes

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
<meta title="viewport" content material="width=device-width, initial-scale=1" />
<hyperlink rel="apple-touch-icon" href="https://hurl.dev/property/img/hurl-icon-120.png" />
...
...
...
    </physique>
</html>

error: Assert failure
  --> take a look at.hurl:4:0
   |
 4 | header "Management-Safety-Coverage" accommodates "default-src 'self'" 
   |   precise:   none
   |   anticipated: accommodates string <default-src 'self'>
   |

take a look at.hurl: Failure (1 request(s) in 146 ms)
--------------------------------------------------------------------------------
Executed information:  1
Succeeded information: 0 (0.0%)
Failed information:    1 (100.0%)
Length:        148 ms

On this instance, we are able to see that there’s really a Content material-Safety-Coverage whereas we’re querying a Management-Safety-Coverage
header. The bug is now actually easy to unravel as a result of the response headers and physique are logged.

This selection is actually helpful in CI/CD the place you wish to have all of the accessible context to debug your session, with out
re-running your assessments. Beware that, because the physique response is logged, the log will be actually lengthy.

Textual asserts in Hurl work by mechanically decoding the response physique bytes, primarily based on the Content material-Sort response header.
That means, if we now have a Latin 1 encoded HTML or an UFT-8 encoded HTML we are able to write the identical assert with none encoding concern:


GET https://instance.org/charset/utf8
HTTP 200
Content material-Sort: textual content/html; charset=utf-8

physique == "<p>café</p>"


GET https://instance.org/charset/latin1
HTTP 200
Content material-Sort: textual content/html; charset=latin1

physique == "<p>café</p>"

To decode a response from bytes to textual content, Hurl makes use of charset trace from Content material-Sort response header. However typically the Content material-Sort
response header doesn’t specify any encoding. Or the encoding is indicated contained in the HTML doc via <meta> tag:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv='Content material-Sort' content material="textual content/html; charset=gb2312">
    </head>
    <physique>你好世界</physique>
</html>

On this case, a decode filter can now be used to explicitly decodes bytes to textual content and do checks:

GET https://instance.com/hello_gb231
HTTP 200

header "Content material-Sort" == "textual content/html"
bytes accommodates hex,c4e3bac3cac0bde7; 
bytes decode "gb2312" xpath "string(//physique)" == "你好世界"

As hinted within the earlier Hurl snippet, now you can consider XPath expression on response half with a xpath filter.

See Also

In Hurl 4.0.0, we’ve barely modified the analysis of JSONPath question. There is no such thing as a correct specs for JSONPath.
The de-facto one, that Hurl tries to comply with as carefully as doable, continues to be https://goessner.net/articles/JsonPath/.
There are just a few edge circumstances for which a number of implementations differ. For example, commonplace JSONPath at all times returns a set,
which more often than not shouldn’t be significant, and more durable to check. Some implementations (such because the Java library https://github.com/json-path/JsonPath)
additionally distinguish between node worth (particular path) and assortment (indefinite path).

Principally, in Hurl 4.0.0, the one selectors returning a price are:

  • array index selector ($.retailer.ebook[2])
  • object key selector ($.retailer.bicycle.shade/$.retailer.bicycle['color'])

Different selectors, that use filters (for example ?(@.worth >= 10) or $[*].id) will return a set. You may then use
nth filter to extract a price from this assortment.

GET https://instance.com/books
HTTP 200

jsonpath "$.retailer.ebook[0].title" == "Dune"
jsonpath "$.retailer.ebook[*].title" nth 0 == "Dune"

Hurl 4.0.0 helps now any customized HTTP technique. The one constraint is to put in writing the tactic in uppercase. You may right-away
experiment the incoming new QUERY method:

QUERY https://instance.org/contacts
Content material-Sort: instance/question
Settle for: textual content/csv
HTTP 200
Content material-Sort: textual content/csv
```
surname, givenname, e-mail
Smith, John, john.smith@instance.org
Jones, Sally, sally.jones@instance.com
Dubois, Camille, camille.dubois@instance.web
```

There are different enhancements and bug fixes, you possibly can verify a whole record in our release note.
In case you like Hurl, don’t hesitate to give us a star on GitHub or share it on Twitter!

We’ll be pleased to listen to from you, both for enhancement requests or for sharing your success story utilizing Hurl!



Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top