mirror of
https://github.com/vale981/lack
synced 2025-03-04 17:01:41 -05:00
Add more tests of lack-middleware-static.
This commit is contained in:
parent
7106525601
commit
d4ef9abc2e
2 changed files with 39 additions and 4 deletions
|
@ -8,7 +8,8 @@
|
||||||
:license "LLGPL"
|
:license "LLGPL"
|
||||||
:depends-on (:lack
|
:depends-on (:lack
|
||||||
:lack-test
|
:lack-test
|
||||||
:prove)
|
:prove
|
||||||
|
:alexandria)
|
||||||
:components ((:test-file "t/middleware/static"))
|
:components ((:test-file "t/middleware/static"))
|
||||||
|
|
||||||
:defsystem-depends-on (:prove-asdf)
|
:defsystem-depends-on (:prove-asdf)
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
(:use :cl
|
(:use :cl
|
||||||
:prove
|
:prove
|
||||||
:lack
|
:lack
|
||||||
:lack.test))
|
:lack.test)
|
||||||
|
(:import-from :alexandria
|
||||||
|
:starts-with-subseq))
|
||||||
(in-package :t.lack.middleware.static)
|
(in-package :t.lack.middleware.static)
|
||||||
|
|
||||||
(plan 1)
|
(plan 3)
|
||||||
|
|
||||||
(subtest "static middleware"
|
(subtest ":path is string"
|
||||||
(let ((app
|
(let ((app
|
||||||
(builder
|
(builder
|
||||||
(:static :path "/public/"
|
(:static :path "/public/"
|
||||||
|
@ -34,4 +36,36 @@
|
||||||
(is (getf headers :content-type) "text/plain")
|
(is (getf headers :content-type) "text/plain")
|
||||||
(is body '("Happy Valentine!")))))
|
(is body '("Happy Valentine!")))))
|
||||||
|
|
||||||
|
(subtest ":path is NIL"
|
||||||
|
(let ((app
|
||||||
|
(builder
|
||||||
|
(:static :path nil
|
||||||
|
:root (asdf:system-relative-pathname :lack #P"data/"))
|
||||||
|
(lambda (env)
|
||||||
|
(declare (ignore env))
|
||||||
|
`(200 (:content-type "text/plain") ("ok"))))))
|
||||||
|
(destructuring-bind (status headers body)
|
||||||
|
(funcall app (generate-env "/public/jellyfish.jpg"))
|
||||||
|
(is status 200)
|
||||||
|
(is (getf headers :content-type) "text/plain")
|
||||||
|
(is body '("ok")))))
|
||||||
|
|
||||||
|
(subtest ":path is function"
|
||||||
|
(let ((app
|
||||||
|
(builder
|
||||||
|
(:static :path (lambda (path-info)
|
||||||
|
(when (starts-with-subseq "/static/" path-info)
|
||||||
|
(subseq path-info #.(length "/static"))))
|
||||||
|
:root (asdf:system-relative-pathname :lack #P"data/"))
|
||||||
|
(lambda (env)
|
||||||
|
(declare (ignore env))
|
||||||
|
`(200 (:content-type "text/plain") ("ok"))))))
|
||||||
|
(destructuring-bind (status headers body)
|
||||||
|
(funcall app (generate-env "/static/jellyfish.jpg"))
|
||||||
|
(is status 200)
|
||||||
|
(is (getf headers :content-type) "image/jpeg")
|
||||||
|
(is body (asdf:system-relative-pathname :lack #P"data/jellyfish.jpg")))
|
||||||
|
|
||||||
|
(is (car (funcall app (generate-env "/static/not-found.png"))) 404)))
|
||||||
|
|
||||||
(finalize)
|
(finalize)
|
||||||
|
|
Loading…
Add table
Reference in a new issue