Add tests for lack.middleware.static.

This commit is contained in:
Eitaro Fukamachi 2015-03-07 04:21:10 +09:00
parent 3b402210fe
commit 3751d2ceda
5 changed files with 59 additions and 0 deletions

1
data/file.txt Normal file
View file

@ -0,0 +1 @@
This is a text for test.

BIN
data/jellyfish.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

BIN
data/redhat.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View 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
View 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)