Add test for set-routes
This commit is contained in:
parent
234b2e50f3
commit
7641ec5f61
10 changed files with 115 additions and 9 deletions
|
@ -26,6 +26,7 @@ src/
|
|||
hello.lisp
|
||||
users/
|
||||
index.lisp
|
||||
<id>.lisp
|
||||
nested/
|
||||
page.lisp
|
||||
```
|
||||
|
|
1
qlfile
1
qlfile
|
@ -1,4 +1,5 @@
|
|||
ql ningle
|
||||
ql lack
|
||||
ql cl-ppcre
|
||||
ql alexandria
|
||||
github rove fukamachi/rove
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
(:class qlot/source/ql:source-ql
|
||||
:initargs (:%version :latest)
|
||||
:version "ql-2023-10-21"))
|
||||
("lack" .
|
||||
(:class qlot/source/ql:source-ql
|
||||
:initargs (:%version :latest)
|
||||
:version "ql-2024-10-12"))
|
||||
("cl-ppcre" .
|
||||
(:class qlot/source/ql:source-ql
|
||||
:initargs (:%version :latest)
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
(defpackage #:ningle-fbr-test/router
|
||||
(:use #:cl
|
||||
#:rove)
|
||||
(:import-from #:ningle)
|
||||
(:import-from #:lack)
|
||||
(:import-from #:lack/test
|
||||
#:testing-app
|
||||
#:request)
|
||||
(:import-from #:ningle-fbr/router
|
||||
#:pathname->path
|
||||
#:path->uri
|
||||
#:path->package))
|
||||
#:path->package
|
||||
#:pathname->path
|
||||
#:set-routes))
|
||||
(in-package #:ningle-fbr-test/router)
|
||||
|
||||
(deftest router-test
|
||||
(testing "pathname->path"
|
||||
(ok (string= (pathname->path #P"/home/app/src/routes/foo.lisp"
|
||||
#P"/home/app/src/routes/")
|
||||
"/foo"))))
|
||||
|
||||
(deftest uri-test
|
||||
(testing "normal path"
|
||||
(ok (string= (path->uri "/foo") "/foo"))
|
||||
|
@ -24,7 +24,7 @@
|
|||
|
||||
(testing "dynamic path"
|
||||
(ok (string= (path->uri "/user/<id>") "/user/:id"))
|
||||
(ok (string= (path->uri "/location/<country>/<city>") "/location/:country/:city" ))))
|
||||
(ok (string= (path->uri "/location/<country>/<city>") "/location/:country/:city"))))
|
||||
|
||||
(deftest package-test
|
||||
(testing "normal case"
|
||||
|
@ -32,3 +32,52 @@
|
|||
:app/routes/foo))
|
||||
(ok (eq (path->package "/foo" :app "somedir/routes")
|
||||
:app/somedir/routes/foo))))
|
||||
|
||||
(deftest router-test
|
||||
(testing "pathname->path"
|
||||
(ok (string= (pathname->path #P"/home/app/src/routes/foo.lisp"
|
||||
#P"/home/app/src/routes/")
|
||||
"/foo")))
|
||||
|
||||
(testing "set-routes"
|
||||
(testing-app (let ((app (make-instance 'ningle:app)))
|
||||
(set-routes app
|
||||
:system :ningle-fbr-test
|
||||
:target-dir-path "routes")
|
||||
(lack:builder app))
|
||||
(multiple-value-bind (body status headers)
|
||||
(request "/")
|
||||
(declare (ignore headers))
|
||||
(ok (string= body "ok"))
|
||||
(ok (eql status 200)))
|
||||
|
||||
(multiple-value-bind (body status headers)
|
||||
(request "/hello")
|
||||
(declare (ignore headers))
|
||||
(ok (string= body "ok"))
|
||||
(ok (eql status 200)))
|
||||
|
||||
(multiple-value-bind (body status headers)
|
||||
(request "/nested/page")
|
||||
(declare (ignore headers))
|
||||
(ok (string= body "ok"))
|
||||
(ok (eql status 200)))
|
||||
|
||||
(multiple-value-bind (body status headers)
|
||||
(request "/users")
|
||||
(declare (ignore headers))
|
||||
(ok (string= body "ok"))
|
||||
(ok (eql status 200)))
|
||||
|
||||
(multiple-value-bind (body status headers)
|
||||
(request "/users/bob")
|
||||
(declare (ignore headers))
|
||||
(ok (string= body "bob"))
|
||||
(ok (eql status 200)))
|
||||
|
||||
(multiple-value-bind (body status headers)
|
||||
(request "/missing")
|
||||
(declare (ignore headers))
|
||||
(ok (string= body "Not Found"))
|
||||
(ok (eql status 404))))))
|
||||
|
||||
|
|
8
tests/routes/hello.lisp
Normal file
8
tests/routes/hello.lisp
Normal file
|
@ -0,0 +1,8 @@
|
|||
(defpackage #:ningle-fbr-test/routes/hello
|
||||
(:use #:cl)
|
||||
(:export #:handle-get))
|
||||
(in-package #:ningle-fbr-test/routes/hello)
|
||||
|
||||
(defun handle-get (params)
|
||||
(declare (ignore params))
|
||||
"ok")
|
8
tests/routes/index.lisp
Normal file
8
tests/routes/index.lisp
Normal file
|
@ -0,0 +1,8 @@
|
|||
(defpackage #:ningle-fbr-test/routes/index
|
||||
(:use #:cl)
|
||||
(:export #:handle-get))
|
||||
(in-package #:ningle-fbr-test/routes/index)
|
||||
|
||||
(defun handle-get (params)
|
||||
(declare (ignore params))
|
||||
"ok")
|
8
tests/routes/nested/page.lisp
Normal file
8
tests/routes/nested/page.lisp
Normal file
|
@ -0,0 +1,8 @@
|
|||
(defpackage #:ningle-fbr-test/routes/nested/page
|
||||
(:use #:cl)
|
||||
(:export #:handle-get))
|
||||
(in-package #:ningle-fbr-test/routes/nested/page)
|
||||
|
||||
(defun handle-get (params)
|
||||
(declare (ignore params))
|
||||
"ok")
|
11
tests/routes/not-found.lisp
Normal file
11
tests/routes/not-found.lisp
Normal file
|
@ -0,0 +1,11 @@
|
|||
(defpackage #:ningle-fbr-test/routes/not-found
|
||||
(:use #:cl)
|
||||
(:import-from #:lack/response)
|
||||
(:import-from #:ningle)
|
||||
(:export #:handle-not-found))
|
||||
(in-package #:ningle-fbr-test/routes/not-found)
|
||||
|
||||
(defun handle-not-found ()
|
||||
(setf (lack/response:response-status ningle:*response*)
|
||||
404)
|
||||
"Not Found")
|
8
tests/routes/users/<id>.lisp
Normal file
8
tests/routes/users/<id>.lisp
Normal file
|
@ -0,0 +1,8 @@
|
|||
(defpackage #:ningle-fbr-test/routes/users/<id>
|
||||
(:use #:cl)
|
||||
(:export #:handle-get))
|
||||
(in-package #:ningle-fbr-test/routes/users/<id>)
|
||||
|
||||
(defun handle-get (params)
|
||||
(let ((id (cdr (assoc :id params))))
|
||||
id))
|
8
tests/routes/users/index.lisp
Normal file
8
tests/routes/users/index.lisp
Normal file
|
@ -0,0 +1,8 @@
|
|||
(defpackage #:ningle-fbr-test/routes/users/index
|
||||
(:use #:cl)
|
||||
(:export #:handle-get))
|
||||
(in-package #:ningle-fbr-test/routes/users/index)
|
||||
|
||||
(defun handle-get (params)
|
||||
(declare (ignore params))
|
||||
"ok")
|
Loading…
Reference in a new issue