mirror of
https://github.com/metosin/reitit.git
synced 2025-12-21 10:01:11 +00:00
test interceptor call counts
This commit is contained in:
parent
e25c90010d
commit
34f0e24bb3
1 changed files with 23 additions and 0 deletions
|
|
@ -420,3 +420,26 @@
|
||||||
(is (= "text/xml" (get-in @result [:headers "Content-Type"])))
|
(is (= "text/xml" (get-in @result [:headers "Content-Type"])))
|
||||||
(is (get-in @result [:headers "Last-Modified"]))
|
(is (get-in @result [:headers "Last-Modified"]))
|
||||||
(is (= "<xml><hello>file</hello></xml>\n" (slurp (:body @result))))))))))))
|
(is (= "<xml><hello>file</hello></xml>\n" (slurp (:body @result))))))))))))
|
||||||
|
|
||||||
|
(deftest execution-times-test
|
||||||
|
(let [times (atom {})
|
||||||
|
response {:status 200, :body "pong"}
|
||||||
|
interceptor (fn [x] {:enter (fn [ctx] (swap! times update-in [:enter x] (fnil inc 0)) ctx)
|
||||||
|
:leave (fn [ctx] (swap! times update-in [:leave x] (fnil inc 0)) ctx)})
|
||||||
|
app (http/ring-handler
|
||||||
|
(http/router
|
||||||
|
["/api"
|
||||||
|
{:interceptors [(interceptor :api)]}
|
||||||
|
["/ping"
|
||||||
|
{:interceptors [(interceptor :ping)]
|
||||||
|
:get {:interceptors [(interceptor :get)]
|
||||||
|
:handler (fn [_] response)}}]])
|
||||||
|
(ring/routes
|
||||||
|
(ring/create-default-handler)
|
||||||
|
{:data {:interceptors [(interceptor :router)]}})
|
||||||
|
{:executor sieppari/executor
|
||||||
|
:interceptors [(interceptor :top)]})]
|
||||||
|
(is (= response (app {:request-method :get, :uri "/api/ping"})))
|
||||||
|
(is (= {:enter {:top 1, :api 1, :ping 1, :get 1}
|
||||||
|
:leave {:get 1, :ping 1, :api 1, :top 1}}
|
||||||
|
@times))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue