Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding first test for the http server - #50 #51

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions console/tests/main.ark
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

# no tests to do as this is only visual and cosmetics

(console:color "grey") (print "text color: grey") (console:color "reset")
(console:color "red") (print "text color: red") (console:color "reset")
(console:color "green") (print "text color: green") (console:color "reset")
(console:color "yellow") (print "text color: yellow") (console:color "reset")
(console:color "blue") (print "text color: blue") (console:color "reset")
(console:color "magenta") (print "text color: magenta") (console:color "reset")
(console:color "cyan") (print "text color: cyan") (console:color "reset")
(console:color "white") (print "text color: white") (console:color "reset")
(console:color "bright_grey") (print "text color: bright_grey") (console:color "reset")
(console:color "bright_red") (print "text color: bright_red") (console:color "reset")
(console:color "bright_green") (print "text color: bright_green") (console:color "reset")
(console:color "bright_yellow") (print "text color: bright_yellow") (console:color "reset")
(console:color "bright_blue") (print "text color: bright_blue") (console:color "reset")
(console:color "bright_magenta") (print "text color: bright_magenta") (console:color "reset")
(console:color "bright_cyan") (print "text color: bright_cyan") (console:color "reset")
(console:color "bright_white") (print "text color: bright_white") (console:color "reset")
(console:color "grey") (print "text color: grey")
(console:color "red") (print "text color: red")
(console:color "green") (print "text color: green")
(console:color "yellow") (print "text color: yellow")
(console:color "blue") (print "text color: blue")
(console:color "magenta") (print "text color: magenta")
(console:color "cyan") (print "text color: cyan")
(console:color "white") (print "text color: white")
(console:color "on_grey") (print "bg color: grey")
(console:color "on_red") (print "bg color: red")
(console:color "on_green") (print "bg color: green")
(console:color "on_yellow") (print "bg color: yellow")
(console:color "on_blue") (print "bg color: blue")
(console:color "on_magenta") (print "bg color: magenta")
(console:color "on_cyan") (print "bg color: cyan")
(console:color "on_white") (print "bg color: white")

(console:color "reset")
37 changes: 34 additions & 3 deletions http/tests/main.ark
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
# TODO add real tests
(let do_nothing nil)
(import "http.arkm")

(print "HTTP tests done")
(http:server:create)

(http:server:get "/hi" (fun (matches body params) {
[
200
(if (empty? body)
"hello world"
(+ "hello, " body))
"text/plain"
]
}))

(http:server:get "/numbers/(\\d+)" (fun (matches body params) {
(let number (toNumber (@ matches 0)))

[200 (toString (+ 12 number)) "text/plain"]
}))

(http:server:get "/stop" (fun (matches body params) {
(http:server:stop)
[200 "stopped" "text/plain"]
}))

(let handler (fun (matches body params) {
(let str_params (if (nil? str_params) "nil" (toString (http:params:toList params))))
[200 (+ (toString matches) "-" body "-" str_params) "text/plain"]
}))

(http:server:post "/post" handler)
(http:server:put "/put" handler)
(http:server:delete "/delete" handler)

(http:server:listen "localhost" 8080)
52 changes: 50 additions & 2 deletions http/tests/run
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,53 @@
ARKSCRIPT=$1
ARKLIB=$2

# todo, see #50
$ARKSCRIPT main.ark --lib $ARKLIB
($ARKSCRIPT main.ark --lib $ARKLIB &)

echo "GET /hi"
res=$(curl -s -X GET http://localhost:8080/hi)
if [[ $res != "hello world" ]]; then
echo "Got $res"
exit 1
fi

echo "GET /hi john"
res=$(curl -s -X GET --data 'john' http://localhost:8080/hi)
if [[ $res != "hello, john" ]]; then
echo "Got $res"
exit 1
fi

echo "GET /numbers/4"
res=$(curl -s -X GET http://localhost:8080/numbers/4)
if [[ $res != "16" ]]; then
echo "Got $res"
exit 1
fi

echo "POST /post john"
res=$(curl -s -X POST --data 'john' http://localhost:8080/post)
if [[ $res != "nil-john-nil" ]]; then
echo "Got $res"
exit 1
fi

echo "PUT /put john"
res=$(curl -s -X PUT --data 'john' http://localhost:8080/put)
if [[ $res != "nil-john-nil" ]]; then
echo "Got $res"
exit 1
fi

echo "DELETE /delete john"
res=$(curl -s -X DELETE --data 'john' http://localhost:8080/delete)
if [[ $res != "nil-john-nil" ]]; then
echo "Got $res"
exit 1
fi

echo "GET /stop"
res=$(curl -s -X GET http://localhost:8080/stop)
if [[ $res != "stopped" ]]; then
echo "Got $res"
exit 1
fi