tests/http.min
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
'min-test require :test
;;;
"http" test.describe
"postman-echo.com" :host
"https://$1" (host) => % :url
("$1/get" (url) => % get-content from-json "headers" dict.get "user-agent" dict.get "min http-module/$1" (version) => % ==) test.assert
("$1/get?test=Hello!" (url) => % "tests/test1.json" :file file download file fs.read from-json "args" dict.get "test" dict.get "Hello!" ==) test.assert
"tests/test1.json" sys.rm
(
{} (
("$1/get" (url) => % "url" dict.set)
("GET" "method" dict.set)
({"it-it" :Accept-Language} "headers" dict.set)
(request)
) tap "body" dict.get from-json "headers" dict.get "accept-language" dict.get "it-it" ==
) test.assert
(
{} (
("$1/put" (url) => % "url" dict.set)
("PUT" "method" dict.set)
({} to-json "body" dict.set)
(request)
) tap "body" dict.get from-json "data" dict.get {} ==
) test.assert
(
{} (
("$1/post" (url) => % "url" dict.set)
("POST" "method" dict.set)
({"post" :test} to-json "body" dict.set)
(request)
) tap "headers" dict.get "content-type" dict.get "^application/json" match?
) test.assert
(
{} (
("$1/patch" (url) => % "url" dict.set)
("PATCH" "method" dict.set)
({} to-json "body" dict.set)
(request)
) tap "body" dict.get from-json "data" dict.get {} ==
) test.assert
(
{} (
("$1/delete" (url) => % "url" dict.set)
("DELETE" "method" dict.set)
(request)
) tap "body" dict.get from-json "url" dict.get "https?:\\/\\/$1/delete" (host) => % match?
) test.assert
test.report
stack.clear
|