diff --git a/README.org b/README.org index 2379e8b..6fd04f4 100644 --- a/README.org +++ b/README.org @@ -38,3 +38,12 @@ The response object is a namespace with the following elements: If your endpoint returns text, you can use ~FromBytes~ from [[https://github.com/mlochbaum/bqn-libs/blob/master/strings.bqn][bqn-libs/strings.bqn]] to decode UTF-8. + +** Tests + +Run a local [[https://httpbin.org/][httpbin.org]] instance with Docker: +#+begin_src sh +docker run -p 8080:80 kennethreitz/httpbin +#+end_src + +The tests can be run with =bqn tests.bqn=. diff --git a/test.bqn b/test.bqn index 00296b8..85a85b8 100644 --- a/test.bqn +++ b/test.bqn @@ -1,11 +1,35 @@ ⟨Get,Post⟩←•Import"curl.bqn" -r←Get"http://localhost:8080/get" -r.code -r.headers -r.content +httpbinURL←"http://localhost:8080" -r←⟨"Content-Type: application/json"⟩Post"http://localhost:8080/post"‿"{""key"": ""value""}" -r.code -r.headers -r.content +•Out " Test GET" +r←Get httpbinURL∾"/get" +! 200=r.code +! 1=⊑"HTTP/"⍷r.headers +! 1=+´"Content-Type: "⍷r.headers +! 1=+´"Content-Length: "⍷r.headers +! 1=+´"""Host"": ""localhost:8080"""⍷r.content +! 1=+´"""User-Agent"": ""curl/bqn"""⍷r.content +! 0=+´"""Hello"": ""World"""⍷r.content +•Out "OK" + +•Out " Test GET with headers" +r↩⟨"User-Agent: toto","Content-Type: application/json","Hello: World"⟩Get httpbinURL∾"/get" +! 200=r.code +! 1=+´"""Host"": ""localhost:8080"""⍷r.content +! 1=+´"""User-Agent"": ""toto"""⍷r.content +! 1=+´"""Content-Type"": ""application/json"""⍷r.content +! 1=+´"""Hello"": ""World"""⍷r.content +•Out "OK" + +•Out " Test POST with headers" +r↩⟨"Content-Type: application/json"⟩Post⟨httpbinURL∾"/post","{""key"": ""value""}"⟩ +! 200=r.code +! 1=⊑"HTTP/"⍷r.headers +! 1=+´"Content-Type: "⍷r.headers +! 1=+´"Content-Length: "⍷r.headers +! 1=+´"""Content-Type"": ""application/json"""⍷r.content +! 1=+´"""data"": ""{\""key\"": \""value\""}"""⍷r.content +•Out "OK" + +•Out "All tests passed."