Skip to content

Commit

Permalink
feat: log failed status code assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Jan 29, 2025
1 parent f99ef47 commit 7c4b321
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
11 changes: 10 additions & 1 deletion rules/assertions.n3
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ prefix log: <http://www.w3.org/2000/10/swap/log#>
} <= {
?res log:includes {
[] a tuner:Response ;
tuner:http_code ?value .
tuner:http_code ?actualValue .
} .

(
{ ?actualValue log:equalTo ?value }
true
{
("Expected status code " ?value " but got " ?actualValue)!string:concatenation^tuner:info .
true log:equalTo false .
}
) log:ifThenElseIn ?SCOPE .
} .

{
Expand Down
35 changes: 35 additions & 0 deletions tests/http_code.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
prefix : <https://api-tuner.described.at/test#http-code/>
PREFIX earl: <http://www.w3.org/ns/earl#>
PREFIX tuner: <https://api-tuner.described.at/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX log: <http://www.w3.org/2000/10/swap/log#>
PREFIX string: <http://www.w3.org/2000/10/swap/string#>

:
a earl:TestCase ;
rdfs:label "Test assertion on status code" ;
.

# Configure a request
:req
a tuner:Request ;
tuner:url <http://localhost:1080/example.com> ;
tuner:method "GET" ;
.

{
:req tuner:response ?res .

?res tuner:http_code 200 .

(
{ ?res tuner:http_code 201 }
{
"Expected assertion failure"^tuner:info .
true log:equalTo false .
}
true
) log:ifThenElseIn ?SCOPE .
} => {
: earl:outcome earl:passed .
} .

0 comments on commit 7c4b321

Please sign in to comment.