-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
;;; copyright (c) 2024 Bruno H. Dias <[email protected]> | ||
|
||
(defpackage #:wst.routing.test | ||
(:use #:cl) | ||
(:import-from #:cl-hash-util | ||
|
@@ -54,4 +52,91 @@ | |
(5am:is (equal "internal server error" | ||
(dispatch-route "/throw-exception" :get nil))) | ||
(remove-route 'throw-exception)) | ||
(5am:run! 'return-internal-server-error-if-exception-is-thrown) | ||
|
||
(5am:def-test build-a-simple-route-using-the-dsl () | ||
(setf wst.routing::*route-specs* nil) | ||
(flet ((the-function () | ||
(5am:is-true t))) | ||
(wst.routing.dsl:build-webserver | ||
'(wst.routing.dsl:route :get index "/" the-function)) | ||
(wst.routing:dispatch-route-by-name 'index '(:request-method :get)))) | ||
|
||
(5am:def-test build-with-just-route-is-the-same-of-just-route-using-the-dsl () | ||
(setf wst.routing::*route-specs* nil) | ||
(let* ((count 0) | ||
(must-be-called (lambda (req res) | ||
(declare (ignore req res)) | ||
(setf count (1+ count))))) | ||
(wst.routing.dsl:build-webserver | ||
`(wst.routing.dsl:wrap | ||
:route (wst.routing.dsl:route :get index "/" ,must-be-called))) | ||
(wst.routing:dispatch-route-by-name 'index '(:request-method :get)) | ||
(5am:is (= 1 count)))) | ||
|
||
(5am:def-test build-route-with-just-before () | ||
(setf wst.routing::*route-specs* nil) | ||
(let* ((count 0) | ||
(must-be-called (lambda (req res) | ||
(declare (ignore req res)) | ||
(setf count (1+ count))))) | ||
(wst.routing.dsl:build-webserver | ||
`(wst.routing.dsl:wrap | ||
:before ,must-be-called | ||
:route (wst.routing.dsl:route :get index "/" ,must-be-called))) | ||
(wst.routing:dispatch-route-by-name 'index '(:request-method :get)) | ||
(5am:is (= 2 count)))) | ||
|
||
(5am:def-test build-route-with-just-after () | ||
(setf wst.routing::*route-specs* nil) | ||
(let* ((count 0) | ||
(must-be-called (lambda (req res) | ||
(declare (ignore req res)) | ||
(setf count (1+ count))))) | ||
(wst.routing.dsl:build-webserver | ||
`(wst.routing.dsl:wrap | ||
:route (wst.routing.dsl:route :get index "/" ,must-be-called) | ||
:after ,must-be-called)) | ||
(wst.routing:dispatch-route-by-name 'index '(:request-method :get)) | ||
(5am:is (= 2 count)))) | ||
|
||
(5am:def-test build-a-route-wrapped-using-the-dsl () | ||
(setf wst.routing::*route-specs* nil) | ||
(let* ((count 0) | ||
(must-be-called (lambda (req res) | ||
(declare (ignore req res)) | ||
(setf count (1+ count))))) | ||
(wst.routing.dsl:build-webserver | ||
`(wst.routing.dsl:wrap | ||
:before ,must-be-called | ||
:route (wst.routing.dsl:route :get index "/" ,must-be-called) | ||
:after ,must-be-called)) | ||
(wst.routing:dispatch-route-by-name 'index '(:request-method :get)) | ||
(5am:is (= 3 count)))) | ||
|
||
(5am:def-test build-group-of-routes-using-the-dsl () | ||
(setf wst.routing::*route-specs* nil) | ||
(let* ((count 0) | ||
(must-be-called (lambda (req res) | ||
(declare (ignore req res)) | ||
(setf count (1+ count))))) | ||
(wst.routing.dsl:build-webserver | ||
`(wst.routing.dsl:group | ||
(wst.routing.dsl:route :get route-a "/a" ,must-be-called) | ||
(wst.routing.dsl:route :get route-b "/b" ,must-be-called))) | ||
(wst.routing:dispatch-route-by-name 'route-a '(:request-method :get)) | ||
(wst.routing:dispatch-route-by-name 'route-b '(:request-method :get)) | ||
(5am:is (= 2 count)))) | ||
|
||
(5am:def-test build-a-resource-routes-using-the-dsl () | ||
(setf wst.routing::*route-specs* nil) | ||
(let* ((count 0) | ||
(must-be-called (lambda (req res) | ||
(declare (ignore req res)) | ||
(setf count (1+ count))))) | ||
(wst.routing.dsl:build-webserver | ||
`(wst.routing.dsl:resource "/base" | ||
(wst.routing.dsl:route :get route-a "/a" ,must-be-called) | ||
(wst.routing.dsl:route :get route-b ,must-be-called))) | ||
(wst.routing:dispatch-route "/base/a" :get '(:request-method :get)) | ||
(wst.routing:dispatch-route "/base" :get '(:request-method :get)) | ||
(5am:is (= 2 count)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters