From a5e6809fcc4c59ef6458eb18ad3ddf15a0bb93b1 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 15:56:45 +0100 Subject: [PATCH 1/8] Test 1-hello --- dune-project | 2 +- test/cram/1-hello.t | 4 ++++ test/cram/README.md | 5 +++++ test/cram/dune | 10 ++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/cram/1-hello.t create mode 100644 test/cram/README.md create mode 100644 test/cram/dune diff --git a/dune-project b/dune-project index 45acd3f0..37f995d6 100644 --- a/dune-project +++ b/dune-project @@ -1 +1 @@ -(lang dune 2.7) +(lang dune 3.0) diff --git a/test/cram/1-hello.t b/test/cram/1-hello.t new file mode 100644 index 00000000..dd024635 --- /dev/null +++ b/test/cram/1-hello.t @@ -0,0 +1,4 @@ + $ hello &> /dev/null & + $ $CURL localhost:8080 + Good morning, world! + $ pkill -P $$ diff --git a/test/cram/README.md b/test/cram/README.md new file mode 100644 index 00000000..cdeeb1bb --- /dev/null +++ b/test/cram/README.md @@ -0,0 +1,5 @@ +# Cram tests guidelines +* Make the example available via the dune file, e.g. `env _ (binaries ../../example/1-hello/hello.exe)))` +* Use `$CURL` instead of `curl` as we need retries in case the server is not yet available. +* Pipe the output of the server to `/dev/null` as it includes timestamps. +* Run `pkill -P $$` to kill the server at the end of the test. diff --git a/test/cram/dune b/test/cram/dune new file mode 100644 index 00000000..befb7b4b --- /dev/null +++ b/test/cram/dune @@ -0,0 +1,10 @@ +(cram + (deps %{bin:hello})) + +(env + (_ + (env-vars + ; --silent: Remove progress bar and error messages from retries + ; --retry 5 --retry-connrefused: retry in case curl is run before the server is available + (CURL "curl --silent --retry 2 --retry-connrefused")) + (binaries ../../example/1-hello/hello.exe))) From bee66a9c3843c93dd71e611e1817a657649cc878 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 15:57:47 +0100 Subject: [PATCH 2/8] Test 2-middleware --- test/cram/2-middleware.t | 4 ++++ test/cram/dune | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 test/cram/2-middleware.t diff --git a/test/cram/2-middleware.t b/test/cram/2-middleware.t new file mode 100644 index 00000000..5edbc4f5 --- /dev/null +++ b/test/cram/2-middleware.t @@ -0,0 +1,4 @@ + $ middleware &> /dev/null & + $ $CURL localhost:8080 + Good morning, world! + $ pkill -P $$ diff --git a/test/cram/dune b/test/cram/dune index befb7b4b..b8c5f8f0 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -1,5 +1,5 @@ (cram - (deps %{bin:hello})) + (deps %{bin:hello} %{bin:middleware})) (env (_ @@ -7,4 +7,6 @@ ; --silent: Remove progress bar and error messages from retries ; --retry 5 --retry-connrefused: retry in case curl is run before the server is available (CURL "curl --silent --retry 2 --retry-connrefused")) - (binaries ../../example/1-hello/hello.exe))) + (binaries + ../../example/1-hello/hello.exe + ../../example/2-middleware/middleware.exe))) From 23d38800a3ed99a88de97dd149f53b3448d52f6f Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 16:00:14 +0100 Subject: [PATCH 3/8] Test 3-router --- test/cram/3-router.t | 4 ++++ test/cram/dune | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 test/cram/3-router.t diff --git a/test/cram/3-router.t b/test/cram/3-router.t new file mode 100644 index 00000000..13823ca4 --- /dev/null +++ b/test/cram/3-router.t @@ -0,0 +1,4 @@ + $ router &> /dev/null & + $ $CURL localhost:8080/echo/hello-world + hello-world + $ pkill -P $$ diff --git a/test/cram/dune b/test/cram/dune index b8c5f8f0..884db5d0 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -1,5 +1,5 @@ (cram - (deps %{bin:hello} %{bin:middleware})) + (deps %{bin:hello} %{bin:middleware} %{bin:router})) (env (_ @@ -9,4 +9,5 @@ (CURL "curl --silent --retry 2 --retry-connrefused")) (binaries ../../example/1-hello/hello.exe - ../../example/2-middleware/middleware.exe))) + ../../example/2-middleware/middleware.exe + ../../example/3-router/router.exe))) From 2f45f3ab43cc688b9a51309639a93095086dfaa3 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 16:14:31 +0100 Subject: [PATCH 4/8] Test 4-counter --- example/4-counter/counter.ml | 2 +- test/cram/4-counter.t | 6 ++++++ test/cram/dune | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 test/cram/4-counter.t diff --git a/example/4-counter/counter.ml b/example/4-counter/counter.ml index 2a1d10ac..bf5559e0 100644 --- a/example/4-counter/counter.ml +++ b/example/4-counter/counter.ml @@ -10,5 +10,5 @@ let () = @@ count_requests @@ Dream.router [ Dream.get "/" (fun _ -> - Dream.html (Printf.sprintf "Saw %i request(s)!" !count)); + Dream.html (Printf.sprintf "Responding to the %i. request!" !count)); ] diff --git a/test/cram/4-counter.t b/test/cram/4-counter.t new file mode 100644 index 00000000..26ceb5b5 --- /dev/null +++ b/test/cram/4-counter.t @@ -0,0 +1,6 @@ + $ counter &> /dev/null & + $ $CURL localhost:8080 + Responding to the 1. request! + $ $CURL localhost:8080 + Responding to the 2. request! + $ pkill -P $$ diff --git a/test/cram/dune b/test/cram/dune index 884db5d0..3f92fef2 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -1,5 +1,5 @@ (cram - (deps %{bin:hello} %{bin:middleware} %{bin:router})) + (deps %{bin:hello} %{bin:middleware} %{bin:router} %{bin:counter})) (env (_ @@ -10,4 +10,5 @@ (binaries ../../example/1-hello/hello.exe ../../example/2-middleware/middleware.exe - ../../example/3-router/router.exe))) + ../../example/3-router/router.exe + ../../example/4-counter/counter.exe))) From 8238a57ca092d9b8c91e2064aebd00e91109fb7b Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 16:22:15 +0100 Subject: [PATCH 5/8] Test 5-promise --- test/cram/5-promise.t | 7 +++++++ test/cram/README.md | 1 + test/cram/dune | 10 ++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/cram/5-promise.t diff --git a/test/cram/5-promise.t b/test/cram/5-promise.t new file mode 100644 index 00000000..e4d5ee3f --- /dev/null +++ b/test/cram/5-promise.t @@ -0,0 +1,7 @@ + $ promise &> /dev/null & + $ $CURL localhost:8080 + 0 request(s) successful
0 request(s) failed + $ curl --no-progress-meter localhost:8080/fail + $ $CURL localhost:8080 + 1 request(s) successful
1 request(s) failed + $ pkill -P $$ diff --git a/test/cram/README.md b/test/cram/README.md index cdeeb1bb..8eb67c92 100644 --- a/test/cram/README.md +++ b/test/cram/README.md @@ -3,3 +3,4 @@ * Use `$CURL` instead of `curl` as we need retries in case the server is not yet available. * Pipe the output of the server to `/dev/null` as it includes timestamps. * Run `pkill -P $$` to kill the server at the end of the test. +* Execute only one test at a time (e.g. `dune runtest -j1`) as the tests all use the same port diff --git a/test/cram/dune b/test/cram/dune index 3f92fef2..b40a377f 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -1,5 +1,10 @@ (cram - (deps %{bin:hello} %{bin:middleware} %{bin:router} %{bin:counter})) + (deps + %{bin:hello} + %{bin:middleware} + %{bin:router} + %{bin:counter} + %{bin:promise})) (env (_ @@ -11,4 +16,5 @@ ../../example/1-hello/hello.exe ../../example/2-middleware/middleware.exe ../../example/3-router/router.exe - ../../example/4-counter/counter.exe))) + ../../example/4-counter/counter.exe + ../../example/5-promise/promise.exe))) From 412c22ba22126b293bd24f1161a78086aae947fc Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Fri, 16 May 2025 16:27:27 +0100 Subject: [PATCH 6/8] Test 6-echo --- test/cram/6-echo.t | 4 ++++ test/cram/dune | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 test/cram/6-echo.t diff --git a/test/cram/6-echo.t b/test/cram/6-echo.t new file mode 100644 index 00000000..e5f8cf41 --- /dev/null +++ b/test/cram/6-echo.t @@ -0,0 +1,4 @@ + $ echo-server &> /dev/null & + $ $CURL localhost:8080/echo --data "Hello, world!" + Hello, world! + $ pkill -P $$ diff --git a/test/cram/dune b/test/cram/dune index b40a377f..c93f6fde 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -4,7 +4,8 @@ %{bin:middleware} %{bin:router} %{bin:counter} - %{bin:promise})) + %{bin:promise} + %{bin:echo-server})) (env (_ @@ -17,4 +18,5 @@ ../../example/2-middleware/middleware.exe ../../example/3-router/router.exe ../../example/4-counter/counter.exe - ../../example/5-promise/promise.exe))) + ../../example/5-promise/promise.exe + (../../example/6-echo/echo.exe as echo-server)))) From b39c8168284c7e3c7d5c13639ae553f9740f80d9 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Sun, 18 May 2025 13:19:26 +0100 Subject: [PATCH 7/8] Fix 7 through d and f --- test/cram/7-template.t | 9 ++ test/cram/8-debug.t | 298 +++++++++++++++++++++++++++++++++++++++++ test/cram/9-error.t | 46 +++++++ test/cram/a-log.t | 5 + test/cram/b-session.t | 6 + test/cram/c-cookie.t | 7 + test/cram/d-form.t | 31 +++++ test/cram/dune | 35 ++++- test/cram/f-static.t | 9 ++ 9 files changed, 444 insertions(+), 2 deletions(-) create mode 100644 test/cram/7-template.t create mode 100644 test/cram/8-debug.t create mode 100644 test/cram/9-error.t create mode 100644 test/cram/a-log.t create mode 100644 test/cram/b-session.t create mode 100644 test/cram/c-cookie.t create mode 100644 test/cram/d-form.t create mode 100644 test/cram/f-static.t diff --git a/test/cram/7-template.t b/test/cram/7-template.t new file mode 100644 index 00000000..ccab89a8 --- /dev/null +++ b/test/cram/7-template.t @@ -0,0 +1,9 @@ + $ template &> /dev/null & + $ $CURL localhost:8080/hello-world + + +

The URL parameter was hello-world!

+ + + + $ pkill -P $$ diff --git a/test/cram/8-debug.t b/test/cram/8-debug.t new file mode 100644 index 00000000..8a703323 --- /dev/null +++ b/test/cram/8-debug.t @@ -0,0 +1,298 @@ + $ debug &> /dev/null & + $ $CURL localhost:8080/bad | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + + + + + + + 400 Bad Request + + + +

An error occured!

+

400 Bad Request

+

+ This error page has been generated by Dream's error handler.
+ Remember to turn debugging mode off when deploying your application in + production. +

+

Debug Dump

+
400 Bad Request
+  
+  From: Application
+  Blame: Client
+  Severity: Warning
+  
+  Client: ::1:
+  
+  GET /bad
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+  dream.params: 
+ + + $ $CURL localhost:8080/fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + + + + + + + 500 Internal Server Error + + + +

An error occured!

+

500 Internal Server Error

+

+ This error page has been generated by Dream's error handler.
+ Remember to turn debugging mode off when deploying your application in + production. +

+

Debug Dump

+
Failure("The Web app failed!")
+  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
+  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  
+  From: Application
+  Blame: Server
+  Severity: Error
+  
+  Client: ::1:
+  
+  GET /fail
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+  dream.params: 
+ + + + + + + + + 500 Internal Server Error + + + +

An error occured!

+

500 Internal Server Error

+

+ This error page has been generated by Dream's error handler.
+ Remember to turn debugging mode off when deploying your application in + production. +

+

Debug Dump

+
Failure("The Web app failed!")
+  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
+  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  
+  From: Application
+  Blame: Server
+  Severity: Error
+  
+  Client: ::1:
+  
+  GET /fail
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+  dream.params: 
+ + + + + + + + + 500 Internal Server Error + + + +

An error occured!

+

500 Internal Server Error

+

+ This error page has been generated by Dream's error handler.
+ Remember to turn debugging mode off when deploying your application in + production. +

+

Debug Dump

+
Failure("The Web app failed!")
+  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
+  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  
+  From: Application
+  Blame: Server
+  Severity: Error
+  
+  Client: ::1:
+  
+  GET /fail
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+  dream.params: 
+ + + $ pkill -P $$ diff --git a/test/cram/9-error.t b/test/cram/9-error.t new file mode 100644 index 00000000..284f242b --- /dev/null +++ b/test/cram/9-error.t @@ -0,0 +1,46 @@ + $ error &> /dev/null & + $ $CURL localhost:8080/bad | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + + +

404 Not Found

+
404 Not Found
+  
+  From: Application
+  Blame: Client
+  Severity: Warning
+  
+  Client: ::1:
+  
+  GET /bad
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+ + + $ $CURL localhost:8080/fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' + + +

404 Not Found

+
404 Not Found
+  
+  From: Application
+  Blame: Client
+  Severity: Warning
+  
+  Client: ::1:
+  
+  GET /fail
+  Host: localhost:8080
+  User-Agent: curl/8.9.1
+  Accept: */*
+  
+  dream.client: ::1:
+  dream.tls: false
+  dream.request_id: 
+ + + $ pkill -P $$ diff --git a/test/cram/a-log.t b/test/cram/a-log.t new file mode 100644 index 00000000..d7f431de --- /dev/null +++ b/test/cram/a-log.t @@ -0,0 +1,5 @@ + $ log &> /dev/null & + $ $CURL localhost:8080 + Good morning, world! + $ $CURL localhost:8080/fail + $ pkill -P $$ diff --git a/test/cram/b-session.t b/test/cram/b-session.t new file mode 100644 index 00000000..030fecfe --- /dev/null +++ b/test/cram/b-session.t @@ -0,0 +1,6 @@ + $ session &> /dev/null & + $ $CURL localhost:8080 -c cookie + You weren't logged in; but now you are! + $ $CURL localhost:8080 -b cookie + Welcome back, alice! + $ pkill -P $$ diff --git a/test/cram/c-cookie.t b/test/cram/c-cookie.t new file mode 100644 index 00000000..a7be6aa5 --- /dev/null +++ b/test/cram/c-cookie.t @@ -0,0 +1,7 @@ + $ cookie &> /dev/null & +The cookie is encrypted so we have cannot set it ourselves + $ $CURL localhost:8080 -c cookie + Set language preference; come again! + $ $CURL localhost:8080 -b cookie + Your preferred language is ut-OP! + $ pkill -P $$ diff --git a/test/cram/d-form.t b/test/cram/d-form.t new file mode 100644 index 00000000..62355ca3 --- /dev/null +++ b/test/cram/d-form.t @@ -0,0 +1,31 @@ + $ form &> /dev/null & + $ $CURL localhost:8080 -c cookies -b cookies | sed 's/value=.*/value=/' + + + + +
+ + + +
+ + + + + $ $CURL localhost:8080 -X POST + $ $CURL localhost:8080 -c cookies -b cookies | sed 's/value=.*/value=/' + + + + +
+ + + +
+ + + + + $ pkill -P $$ diff --git a/test/cram/dune b/test/cram/dune index c93f6fde..787d539d 100644 --- a/test/cram/dune +++ b/test/cram/dune @@ -5,7 +5,23 @@ %{bin:router} %{bin:counter} %{bin:promise} - %{bin:echo-server})) + %{bin:echo-server} + %{bin:template} + %{bin:debug} + %{bin:error} + %{bin:log} + %{bin:session} + %{bin:cookie} + %{bin:form} + %{bin:json} + %{bin:static} + %{bin:upload} + %{bin:sql} + ; TODO reenable + ; %{bin:graphql} + %{bin:stream} + %{bin:websocket} + %{bin:https})) (env (_ @@ -19,4 +35,19 @@ ../../example/3-router/router.exe ../../example/4-counter/counter.exe ../../example/5-promise/promise.exe - (../../example/6-echo/echo.exe as echo-server)))) + (../../example/6-echo/echo.exe as echo-server) + ../../example/7-template/template.exe + ../../example/8-debug/debug.exe + ../../example/9-error/error.exe + ../../example/a-log/log.exe + ../../example/b-session/session.exe + ../../example/c-cookie/cookie.exe + ../../example/d-form/form.exe + ../../example/e-json/json.exe + ../../example/f-static/static.exe + ../../example/g-upload/upload.exe + ../../example/h-sql/sql.exe + ; ../../example/i-graphql/graphql.exe + ../../example/j-stream/stream.exe + ../../example/k-websocket/websocket.exe + ../../example/l-https/https.exe))) diff --git a/test/cram/f-static.t b/test/cram/f-static.t new file mode 100644 index 00000000..8504c8bd --- /dev/null +++ b/test/cram/f-static.t @@ -0,0 +1,9 @@ + $ mkdir testdata + $ echo "Hello" > hello + $ echo "World" > testdata/world + $ static &> /dev/null & + $ $CURL localhost:8080/static/hello + Hello + $ $CURL localhost:8080/static/testdata/world + World + $ pkill -P $$ From 1ec9fb6fcfbf4d4dea22831e58f31b11f841ed08 Mon Sep 17 00:00:00 2001 From: Sebastian Willenbrink Date: Sun, 18 May 2025 13:29:07 +0100 Subject: [PATCH 8/8] Promote test output --- test/cram/8-debug.t | 16 ++++++++++------ test/cram/9-error.t | 6 ++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/test/cram/8-debug.t b/test/cram/8-debug.t index 8a703323..6346b3ff 100644 --- a/test/cram/8-debug.t +++ b/test/cram/8-debug.t @@ -69,6 +69,7 @@ dream.client: ::1: dream.tls: false dream.request_id: + dream.fd: 6 dream.params: @@ -127,8 +128,8 @@

Debug Dump

Failure("The Web app failed!")
-  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
-  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
+  Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
   
   From: Application
   Blame: Server
@@ -144,6 +145,7 @@
   dream.client: ::1:
   dream.tls: false
   dream.request_id: 
+  dream.fd: 6
   dream.params: 
@@ -201,8 +203,8 @@

Debug Dump

Failure("The Web app failed!")
-  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
-  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
+  Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
   
   From: Application
   Blame: Server
@@ -218,6 +220,7 @@
   dream.client: ::1:
   dream.tls: false
   dream.request_id: 
+  dream.fd: 6
   dream.params: 
@@ -275,8 +278,8 @@

Debug Dump

Failure("The Web app failed!")
-  Raised at Dream__server__Log.Make.logger in file "src/server/log.ml", line 542, characters 6-15
-  Called from Dream__server__Catch.catch in file "src/server/catch.ml", line 45, characters 8-28
+  Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
+  Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
   
   From: Application
   Blame: Server
@@ -292,6 +295,7 @@
   dream.client: ::1:
   dream.tls: false
   dream.request_id: 
+  dream.fd: 6
   dream.params: 
diff --git a/test/cram/9-error.t b/test/cram/9-error.t index 284f242b..42eb57fa 100644 --- a/test/cram/9-error.t +++ b/test/cram/9-error.t @@ -18,7 +18,8 @@ dream.client: ::1: dream.tls: false - dream.request_id: + dream.request_id: + dream.fd: 6 $ $CURL localhost:8080/fail | sed 's/::1:.*/::1:/' | sed 's/dream.request_id: [^<]*/dream.request_id: /' @@ -40,7 +41,8 @@ dream.client: ::1: dream.tls: false - dream.request_id: + dream.request_id: + dream.fd: 6 $ pkill -P $$