mirror of
https://github.com/vale981/lack
synced 2025-03-04 17:01:41 -05:00
Add more tests of lack-middleware-backtrace.
This commit is contained in:
parent
d6815bb8ff
commit
55fec82eda
3 changed files with 40 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@
|
||||||
*~
|
*~
|
||||||
.#*
|
.#*
|
||||||
data/test.db
|
data/test.db
|
||||||
|
data/test.log
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
:license "LLGPL"
|
:license "LLGPL"
|
||||||
:depends-on (:lack
|
:depends-on (:lack
|
||||||
:lack-test
|
:lack-test
|
||||||
:prove)
|
:prove
|
||||||
|
:alexandria)
|
||||||
:components
|
:components
|
||||||
((:test-file "t/middleware/backtrace"))
|
((:test-file "t/middleware/backtrace"))
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
:prove))
|
:prove))
|
||||||
(in-package :t.lack.middleware.backtrace)
|
(in-package :t.lack.middleware.backtrace)
|
||||||
|
|
||||||
(plan 4)
|
(plan 6)
|
||||||
|
|
||||||
(let ((app
|
(let ((app
|
||||||
(builder (:backtrace
|
(builder (:backtrace
|
||||||
|
@ -47,11 +47,28 @@
|
||||||
(ok (< 0 (length (get-output-stream-string *error-output*)))
|
(ok (< 0 (length (get-output-stream-string *error-output*)))
|
||||||
"Got backtraces"))))
|
"Got backtraces"))))
|
||||||
|
|
||||||
|
(subtest ":result-on-error is function"
|
||||||
|
(let ((app
|
||||||
|
(builder (:backtrace
|
||||||
|
:result-on-error (lambda (condition)
|
||||||
|
(if (typep condition 'test-error)
|
||||||
|
'(503 (:content-type "text/plain") ("Service Temporary Unavailable"))
|
||||||
|
'(500 (:content-type "text/plain") ("Internal Server Error")))))
|
||||||
|
(lambda (env)
|
||||||
|
(if (string= (getf env :path-info) "/503")
|
||||||
|
(error 'test-error)
|
||||||
|
(error "Error occured")))))
|
||||||
|
(*error-output* (make-broadcast-stream)))
|
||||||
|
(is (funcall app (generate-env "/"))
|
||||||
|
'(500 (:content-type "text/plain") ("Internal Server Error")))
|
||||||
|
(is (funcall app (generate-env "/503"))
|
||||||
|
'(503 (:content-type "text/plain") ("Service Temporary Unavailable")))))
|
||||||
|
|
||||||
(defparameter *test-error-output* (make-string-output-stream))
|
(defparameter *test-error-output* (make-string-output-stream))
|
||||||
|
|
||||||
(subtest "Custom :output"
|
(subtest "Custom :output (stream)"
|
||||||
(let ((app
|
(let ((app
|
||||||
(builder (:backtrace :output '*test-error-output*
|
(builder (:backtrace :output *test-error-output*
|
||||||
:result-on-error '(500 (:content-type "text/plain") ("Internal Server Error")))
|
:result-on-error '(500 (:content-type "text/plain") ("Internal Server Error")))
|
||||||
(lambda (env)
|
(lambda (env)
|
||||||
(declare (ignore env))
|
(declare (ignore env))
|
||||||
|
@ -63,4 +80,21 @@
|
||||||
(ok (< 0 (length (get-output-stream-string *test-error-output*)))
|
(ok (< 0 (length (get-output-stream-string *test-error-output*)))
|
||||||
"Output to the custom :output"))))
|
"Output to the custom :output"))))
|
||||||
|
|
||||||
|
(subtest "Custom :output (pathname)"
|
||||||
|
(let* ((log-file (asdf:system-relative-pathname :lack #P"data/test.log"))
|
||||||
|
(app
|
||||||
|
(builder (:backtrace :output log-file
|
||||||
|
:result-on-error '(500 (:content-type "text/plain") ("Internal Server Error")))
|
||||||
|
(lambda (env)
|
||||||
|
(declare (ignore env))
|
||||||
|
(error "Error occured")))))
|
||||||
|
(when (probe-file log-file)
|
||||||
|
(delete-file log-file))
|
||||||
|
(let ((*error-output* (make-string-output-stream)))
|
||||||
|
(funcall app (generate-env "/"))
|
||||||
|
(ok (= 0 (length (get-output-stream-string *error-output*)))
|
||||||
|
"Don't output to *error-output*")
|
||||||
|
(ok (< 0 (length (alexandria:read-file-into-string log-file)))
|
||||||
|
"Output to the custom :output"))))
|
||||||
|
|
||||||
(finalize)
|
(finalize)
|
||||||
|
|
Loading…
Add table
Reference in a new issue