Refactor tests for better reporting

This commit is contained in:
Dimitri Lozeve 2023-10-02 21:18:10 +02:00
parent 3c42890e15
commit d30021db16

223
tests.bqn
View file

@ -7,12 +7,14 @@
•Import"curl.bqn" •Import"curl.bqn"
httpbinURL"http://localhost:8080" httpbinURL"http://localhost:8080"
r0
## Simple API RunTest{•term.OutRaw (4' ')"Test "𝕨 𝕏 @ •Out ((69-𝕨)'.')"OK"}
RunSuite{•Out 𝕨':' RunTest´¨𝕩 •Out " All "(•Fmt 𝕩)" tests passed."}
RunAll{RunSuite´¨𝕩 •Out "All "(•Fmt +´¨´¨𝕩)" tests passed."}
•Out " Test GET" simpleAPI_testsuite
rGet httpbinURL"/get" "simple GET"{𝕊𝕩:
rGet httpbinURL"/get"
! 200=r.code ! 200=r.code
! 0=r.redirectCount ! 0=r.redirectCount
! 1="HTTP/"r.headers ! 1="HTTP/"r.headers
@ -21,20 +23,20 @@ r↩Get httpbinURL∾"/get"
! 1=+´"""Host"": ""localhost:8080"""r.content ! 1=+´"""Host"": ""localhost:8080"""r.content
! 1=+´"""User-Agent"": ""curl/bqn"""r.content ! 1=+´"""User-Agent"": ""curl/bqn"""r.content
! 0=+´"""Hello"": ""World"""r.content ! 0=+´"""Hello"": ""World"""r.content
•Out "OK" },
"simple GET with headers"{𝕊𝕩:
•Out " Test GET with headers" headers"User-Agent: toto","Content-Type: application/json","Hello: World"
r"User-Agent: toto","Content-Type: application/json","Hello: World"Get httpbinURL"/get" rheaders Get httpbinURL"/get"
! 200=r.code ! 200=r.code
! 0=r.redirectCount ! 0=r.redirectCount
! 1=+´"""Host"": ""localhost:8080"""r.content ! 1=+´"""Host"": ""localhost:8080"""r.content
! 1=+´"""User-Agent"": ""toto"""r.content ! 1=+´"""User-Agent"": ""toto"""r.content
! 1=+´"""Content-Type"": ""application/json"""r.content ! 1=+´"""Content-Type"": ""application/json"""r.content
! 1=+´"""Hello"": ""World"""r.content ! 1=+´"""Hello"": ""World"""r.content
•Out "OK" },
"simple POST with headers"{𝕊𝕩:
•Out " Test POST with headers" headers"Content-Type: application/json"
r"Content-Type: application/json"PosthttpbinURL"/post","{""key"": ""value""}" rheaders Post httpbinURL"/post","{""key"": ""value""}"
! 200=r.code ! 200=r.code
! 0=r.redirectCount ! 0=r.redirectCount
! 1="HTTP/"r.headers ! 1="HTTP/"r.headers
@ -42,144 +44,145 @@ r↩⟨"Content-Type: application/json"⟩Post⟨httpbinURL∾"/post","{""key"":
! 1=+´"Content-Length: "r.headers ! 1=+´"Content-Length: "r.headers
! 1=+´"""Content-Type"": ""application/json"""r.content ! 1=+´"""Content-Type"": ""application/json"""r.content
! 1=+´"""data"": ""{\""key\"": \""value\""}"""r.content ! 1=+´"""data"": ""{\""key\"": \""value\""}"""r.content
•Out "OK" }
## Advanced API advancedAPI_testsuite
"open session"{𝕊𝕩:
•Out " Test open session"
sessionOpenSession @ sessionOpenSession @
! 8=session.sessionPtr ! 8=session.sessionPtr
! (80)session.headersSlist ! (80)session.headersSlist
•Out "OK" CloseSession session
},
•Out " Test GET" "GET"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
rPerform (httpbinURL"/get") SetURL session rPerform (httpbinURL"/get") SetURL session
! 200=r.code ! 200=r.code
! 0=r.redirectCount ! 0=r.redirectCount
! 10r.content ! 10r.content
•Out "OK" CloseSession session
},
•Out " Test POST" "POST"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
rPerform "toto"SetData (httpbinURL"/post") SetURL session rPerform "toto"SetData (httpbinURL"/post") SetURL session
! 200=r.code ! 200=r.code
! 0=r.redirectCount ! 0=r.redirectCount
! 1=+´"toto"r.content ! 1=+´"toto"r.content
•Out "OK" CloseSession session
},
•Out " Test basic auth fail" "basic auth fail"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
session(httpbinURL"/basic-auth/username/s3cr3tpa55word") SetURL session session(httpbinURL"/basic-auth/username/s3cr3tpa55word") SetURL session
rPerform session rPerform session
! 401=r.code ! 401=r.code
•Out "OK" CloseSession session
},
•Out " Test basic auth with header" "basic auth with header"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
session(httpbinURL"/basic-auth/username/s3cr3tpa55word") SetURL session session(httpbinURL"/basic-auth/username/s3cr3tpa55word") SetURL session
rPerform "Authorization: Basic dXNlcm5hbWU6czNjcjN0cGE1NXdvcmQ=" SetHeaders session rPerform "Authorization: Basic dXNlcm5hbWU6czNjcjN0cGE1NXdvcmQ=" SetHeaders session
! 200=r.code ! 200=r.code
•Out "OK" CloseSession session
},
•Out " Test basic auth with URL" "basic auth with URL"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
session("http://username:s3cr3tpa55word@localhost:8080/basic-auth/username/s3cr3tpa55word") SetURL session session("http://username:s3cr3tpa55word@localhost:8080/basic-auth/username/s3cr3tpa55word") SetURL session
rPerform session rPerform session
! 200=r.code ! 200=r.code
•Out "OK" CloseSession session
},
•Out " Test bearer auth fail" "bearer auth fail"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
session(httpbinURL"/bearer") SetURL session session(httpbinURL"/bearer") SetURL session
rPerform session rPerform session
! 401=r.code ! 401=r.code
•Out "OK" CloseSession session
},
•Out " Test bearer auth" "bearer auth"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
session(httpbinURL"/bearer") SetURL session session(httpbinURL"/bearer") SetURL session
rPerform "Authorization: Bearer hey!" SetHeaders session rPerform "Authorization: Bearer hey!" SetHeaders session
! 200=r.code ! 200=r.code
•Out "OK" CloseSession session
},
•Out " Test status GET" "status GET"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
rPerform (httpbinURL"/status/418") SetURL session rPerform (httpbinURL"/status/418") SetURL session
! 418=r.code ! 418=r.code
•Out "OK" CloseSession session
},
•Out " Test status POST" "status POST"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
rPerform ""SetData (httpbinURL"/status/418") SetURL session rPerform ""SetData (httpbinURL"/status/418") SetURL session
! 418=r.code ! 418=r.code
•Out "OK" CloseSession session
},
•Out " Test set headers" "set headers"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
session(httpbinURL"/headers") SetURL session session(httpbinURL"/headers") SetURL session
rPerform "Hello: World" SetHeaders session rPerform "Hello: World" SetHeaders session
! 1=+´"""Hello"": ""World"""r.content ! 1=+´"""Hello"": ""World"""r.content
•Out "OK" CloseSession session
},
•Out " Test default user-agent" "default user-agent"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
session(httpbinURL"/user-agent") SetURL session session(httpbinURL"/user-agent") SetURL session
rPerform session rPerform session
! 1=+´"curl/bqn"r.content ! 1=+´"curl/bqn"r.content
•Out "OK" CloseSession session
},
•Out " Test custom user-agent" "custom user-agent"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
session(httpbinURL"/user-agent") SetURL session session(httpbinURL"/user-agent") SetURL session
rPerform "User-Agent: hello/world" SetHeaders session rPerform "User-Agent: hello/world" SetHeaders session
! 0=+´"curl/bqn"r.content ! 0=+´"curl/bqn"r.content
! 1=+´"hello/world"r.content ! 1=+´"hello/world"r.content
•Out "OK" CloseSession session
},
•Out " Test timeout with fast request" "timeout with fast request"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
session1010 SetTimeoutms (httpbinURL"/delay/1") SetURL session session1010 SetTimeoutms (httpbinURL"/delay/1") SetURL session
rPerform session rPerform session
! 200=r.code ! 200=r.code
•Out "OK" CloseSession session
},
•Out " Test request timeout" "request timeout"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
session100 SetTimeoutms (httpbinURL"/delay/1") SetURL session session100 SetTimeoutms (httpbinURL"/delay/1") SetURL session
! Perform1 session ! Perform1 session
•Out "OK" CloseSession session
},
•Out " Test follow redirects" "follow redirects"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
rPerform (httpbinURL"/redirect/5") SetURL session rPerform (httpbinURL"/redirect/5") SetURL session
! 200=r.code ! 200=r.code
! 5=r.redirectCount ! 5=r.redirectCount
•Out "OK" CloseSession session
},
•Out " Test follow absolute redirects" "follow absolute redirects"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
rPerform (httpbinURL"/absolute-redirect/5") SetURL session rPerform (httpbinURL"/absolute-redirect/5") SetURL session
! 200=r.code ! 200=r.code
! 5=r.redirectCount ! 5=r.redirectCount
•Out "OK" CloseSession session
},
•Out " Test follow relative redirects" "follow relative redirects"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
rPerform (httpbinURL"/relative-redirect/5") SetURL session rPerform (httpbinURL"/relative-redirect/5") SetURL session
! 200=r.code ! 200=r.code
! 5=r.redirectCount ! 5=r.redirectCount
•Out "OK" CloseSession session
},
•Out " Test parameters" "parameters"{𝕊𝕩:
sessionResetSession session sessionOpenSession @
rPerform (httpbinURL"/anything?hello=world&zig=zag") SetURL session rPerform (httpbinURL"/anything?hello=world&zig=zag") SetURL session
! 1=+´"""hello"": ""world"""r.content ! 1=+´"""hello"": ""world"""r.content
! 1=+´"""zig"": ""zag"""r.content ! 1=+´"""zig"": ""zag"""r.content
•Out "OK"
•Out " Test close session"
CloseSession session CloseSession session
•Out "OK" },
•Out "All tests passed." RunAll
"Simple API"simpleAPI_testsuite,
"Advanced API"advancedAPI_testsuite,