mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 17:01:11 +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)
|
(when (and wrap compile)
|
||||||
(throw
|
(throw
|
||||||
(ex-info
|
(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))
|
(map->Middleware m))
|
||||||
|
|
||||||
(extend-protocol IntoMiddleware
|
(extend-protocol IntoMiddleware
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
(testing ":wrap & :compile are exclusive"
|
(testing ":wrap & :compile are exclusive"
|
||||||
(is (thrown-with-msg?
|
(is (thrown-with-msg?
|
||||||
ExceptionInfo
|
ExceptionInfo
|
||||||
#"Middleware can't both :wrap and :compile defined"
|
#"Middleware can't have both :wrap and :compile defined"
|
||||||
(middleware/create
|
(middleware/create
|
||||||
{:name ::test
|
{:name ::test
|
||||||
:wrap identity
|
:wrap identity
|
||||||
|
|
@ -80,6 +80,11 @@
|
||||||
(swap! calls inc)
|
(swap! calls inc)
|
||||||
(fn [request]
|
(fn [request]
|
||||||
[data value request])))}
|
[data value request])))}
|
||||||
|
mw3 {:compile (fn [data _]
|
||||||
|
(swap! calls inc)
|
||||||
|
{:compile (fn [data _]
|
||||||
|
(swap! calls inc)
|
||||||
|
mw)})}
|
||||||
->app (fn [ast handler]
|
->app (fn [ast handler]
|
||||||
(middleware/compile-handler
|
(middleware/compile-handler
|
||||||
(middleware/expand ast :data {})
|
(middleware/expand ast :data {})
|
||||||
|
|
@ -99,6 +104,13 @@
|
||||||
(is (= [:data :value :request] (app :request)))
|
(is (= [:data :value :request] (app :request)))
|
||||||
(is (= 2 @calls)))))
|
(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"
|
(testing "nil unmounts the middleware"
|
||||||
(let [app (->app [{:compile (constantly nil)}
|
(let [app (->app [{:compile (constantly nil)}
|
||||||
{:compile (constantly nil)}] identity)]
|
{:compile (constantly nil)}] identity)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue