mirror of
https://github.com/vale981/lack
synced 2025-03-04 08:51:41 -05:00
Add tests for lack.middleware.static.
This commit is contained in:
parent
3b402210fe
commit
3751d2ceda
5 changed files with 59 additions and 0 deletions
1
data/file.txt
Normal file
1
data/file.txt
Normal file
|
@ -0,0 +1 @@
|
|||
This is a text for test.
|
BIN
data/jellyfish.jpg
Normal file
BIN
data/jellyfish.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 136 KiB |
BIN
data/redhat.png
Normal file
BIN
data/redhat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
18
t-lack-middleware-static.asd
Normal file
18
t-lack-middleware-static.asd
Normal file
|
@ -0,0 +1,18 @@
|
|||
(in-package :cl-user)
|
||||
(defpackage t-lack-middleware-static-asd
|
||||
(:use :cl :asdf))
|
||||
(in-package :t-lack-middleware-static-asd)
|
||||
|
||||
(defsystem t-lack-middleware-static
|
||||
:author "Eitaro Fukamachi"
|
||||
:license "LLGPL"
|
||||
:depends-on (:lack
|
||||
:lack-test
|
||||
:prove
|
||||
:dexador)
|
||||
:components ((:test-file "t/middleware/static"))
|
||||
|
||||
:defsystem-depends-on (:prove-asdf)
|
||||
:perform (test-op :after (op c)
|
||||
(funcall (intern #.(string :run-test-system) :prove-asdf) c)
|
||||
(asdf:clear-system c)))
|
40
t/middleware/static.lisp
Normal file
40
t/middleware/static.lisp
Normal file
|
@ -0,0 +1,40 @@
|
|||
(in-package :cl-user)
|
||||
(defpackage t.lack.middleware.static
|
||||
(:use :cl
|
||||
:prove
|
||||
:lack
|
||||
:lack.test))
|
||||
(in-package :t.lack.middleware.static)
|
||||
|
||||
(defun localhost (path)
|
||||
(format nil "http://localhost:~D~A"
|
||||
*lack-test-port* path))
|
||||
|
||||
(plan nil)
|
||||
|
||||
#+thread-support
|
||||
(subtest-app "static middleware"
|
||||
(builder
|
||||
(:static :path "/public/"
|
||||
:root (asdf:system-relative-pathname :lack #P"data/"))
|
||||
(lambda (env)
|
||||
(declare (ignore env))
|
||||
`(200 (:content-type "text/plain") ("Happy Valentine!"))))
|
||||
(multiple-value-bind (body status headers)
|
||||
(dex:get (localhost "/public/jellyfish.jpg"))
|
||||
(is status 200)
|
||||
(is (gethash "content-type" headers) "image/jpeg")
|
||||
(is (length body) 139616))
|
||||
(multiple-value-bind (body status)
|
||||
(dex:get (localhost "/public/hoge.png"))
|
||||
(is status 404)
|
||||
(is body "Not Found"))
|
||||
(multiple-value-bind (body status headers)
|
||||
(dex:get (localhost "/"))
|
||||
(is status 200)
|
||||
(is (gethash "content-type" headers) "text/plain")
|
||||
(is body "Happy Valentine!")))
|
||||
#-thread-support
|
||||
(skip 1 "because your lisp doesn't support threads")
|
||||
|
||||
(finalize)
|
Loading…
Add table
Reference in a new issue