mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 00:41:12 +00:00
Test for deeply compiled middleware
This commit is contained in:
parent
22bbe38b8c
commit
259c8e01bb
2 changed files with 14 additions and 2 deletions
|
|
@ -13,7 +13,7 @@
|
|||
(when (and wrap compile)
|
||||
(throw
|
||||
(ex-info
|
||||
(str "Middleware can't both :wrap and :compile defined " m) m)))
|
||||
(str "Middleware can't have both :wrap and :compile defined " m) m)))
|
||||
(map->Middleware m))
|
||||
|
||||
(extend-protocol IntoMiddleware
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
(testing ":wrap & :compile are exclusive"
|
||||
(is (thrown-with-msg?
|
||||
ExceptionInfo
|
||||
#"Middleware can't both :wrap and :compile defined"
|
||||
#"Middleware can't have both :wrap and :compile defined"
|
||||
(middleware/create
|
||||
{:name ::test
|
||||
:wrap identity
|
||||
|
|
@ -80,6 +80,11 @@
|
|||
(swap! calls inc)
|
||||
(fn [request]
|
||||
[data value request])))}
|
||||
mw3 {:compile (fn [data _]
|
||||
(swap! calls inc)
|
||||
{:compile (fn [data _]
|
||||
(swap! calls inc)
|
||||
mw)})}
|
||||
->app (fn [ast handler]
|
||||
(middleware/compile-handler
|
||||
(middleware/expand ast :data {})
|
||||
|
|
@ -99,6 +104,13 @@
|
|||
(is (= [:data :value :request] (app :request)))
|
||||
(is (= 2 @calls)))))
|
||||
|
||||
(testing "deeply compiled Middleware"
|
||||
(reset! calls 0)
|
||||
(let [app (->app [[(middleware/create mw3) :value]] identity)]
|
||||
(dotimes [_ 10]
|
||||
(is (= [:data :value :request] (app :request)))
|
||||
(is (= 4 @calls)))))
|
||||
|
||||
(testing "nil unmounts the middleware"
|
||||
(let [app (->app [{:compile (constantly nil)}
|
||||
{:compile (constantly nil)}] identity)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue