mirror of
https://github.com/vale981/lack
synced 2025-03-04 17:01:41 -05:00
add test of lack.middleware.mount.
This commit is contained in:
parent
593f8b6d88
commit
5f2ffe52fe
2 changed files with 91 additions and 0 deletions
19
t-lack-middleware-mount.asd
Normal file
19
t-lack-middleware-mount.asd
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
(in-package :cl-user)
|
||||||
|
(defpackage t-lack-middleware-mount-asd
|
||||||
|
(:use :cl :asdf))
|
||||||
|
(in-package :t-lack-middleware-mount-asd)
|
||||||
|
|
||||||
|
(defsystem t-lack-middleware-mount
|
||||||
|
:author "Rudolph Miller"
|
||||||
|
:license "LLGPL"
|
||||||
|
:depends-on (:lack
|
||||||
|
:lack-test
|
||||||
|
:lack-component
|
||||||
|
:lack-middleware-mount
|
||||||
|
:prove)
|
||||||
|
:components
|
||||||
|
((:test-file "t/middleware/mount"))
|
||||||
|
|
||||||
|
:defsystem-depends-on (:prove-asdf)
|
||||||
|
:perform (test-op :after (op c)
|
||||||
|
(funcall (intern #.(string :run-test-system) :prove) c)))
|
72
t/middleware/mount.lisp
Normal file
72
t/middleware/mount.lisp
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
(in-package :cl-user)
|
||||||
|
(defpackage t.lack.middleware.mount
|
||||||
|
(:use :cl
|
||||||
|
:lack
|
||||||
|
:lack.test
|
||||||
|
:lack.component
|
||||||
|
:prove))
|
||||||
|
(in-package :t.lack.middleware.mount)
|
||||||
|
|
||||||
|
(plan 2)
|
||||||
|
|
||||||
|
(defclass test-component (lack-component) ())
|
||||||
|
|
||||||
|
(defmethod call ((app test-component) env)
|
||||||
|
(declare (ignore env))
|
||||||
|
'(200 () "mount2"))
|
||||||
|
|
||||||
|
(subtest "dispatch"
|
||||||
|
(macrolet ((mount-test (component)
|
||||||
|
`(let* ((not-mounted '(200 () ("not-mounted")))
|
||||||
|
(app
|
||||||
|
(builder
|
||||||
|
(:mount "/mount" ,component)
|
||||||
|
(lambda (env)
|
||||||
|
(declare (ignore env))
|
||||||
|
not-mounted))))
|
||||||
|
(let ((expected (funcall (to-app ,component) (generate-env "/")))
|
||||||
|
(result1 (funcall app (generate-env "/mount")))
|
||||||
|
(result2 (funcall app (generate-env "/mount/test")))
|
||||||
|
(result3 (funcall app (generate-env "/test"))))
|
||||||
|
(is result1
|
||||||
|
expected
|
||||||
|
"string=.")
|
||||||
|
|
||||||
|
(is result2
|
||||||
|
expected
|
||||||
|
"subseq.")
|
||||||
|
|
||||||
|
(is result3
|
||||||
|
not-mounted
|
||||||
|
"t.")))))
|
||||||
|
(subtest "(lambda (env) ...)"
|
||||||
|
(mount-test
|
||||||
|
(lambda (env)
|
||||||
|
(declare (ignore env))
|
||||||
|
'(200 () ("mount")))))
|
||||||
|
(subtest "lack-component"
|
||||||
|
(mount-test (make-instance 'test-component)))))
|
||||||
|
|
||||||
|
(subtest "path-info"
|
||||||
|
(macrolet ((is-path-info (env expected &optional comment)
|
||||||
|
`(is (getf ,env :path-info)
|
||||||
|
,expected
|
||||||
|
,@(when comment (list comment)))))
|
||||||
|
(let* ((response '(200 () ("ok")))
|
||||||
|
(app
|
||||||
|
(builder
|
||||||
|
(:mount "/mount1"
|
||||||
|
(lambda (env)
|
||||||
|
(is-path-info env "/" "string=.")
|
||||||
|
response))
|
||||||
|
(:mount "/mount2"
|
||||||
|
(lambda (env)
|
||||||
|
(is-path-info env "/test" "subseq.")
|
||||||
|
response))
|
||||||
|
(lambda (env)
|
||||||
|
(is-path-info env "/test" "t.")
|
||||||
|
response))))
|
||||||
|
(dolist (path (list "/mount1" "/mount2/test" "/test"))
|
||||||
|
(funcall app (generate-env path))))))
|
||||||
|
|
||||||
|
(finalize)
|
Loading…
Add table
Reference in a new issue