Permalink
Browse files

Test for config middleware

  • Loading branch information...
1 parent 51bf6ad commit 266a0cbc6294a6f4a8952af1be967903296f858c David Leatherman committed Feb 5, 2013
Showing with 28 additions and 1 deletion.
  1. +2 −1 etc/config.clj
  2. +26 −0 test/carica/test/core.clj
View
@@ -1,2 +1,3 @@
{:from-etc true
- :merged-val "etc"}
+ :merged-val "etc"
+ :eval-cfg (+ 1 1)}
@@ -69,3 +69,29 @@
(deftest nil-resources-are-handled
(is (= (get-configs [(resources "config.clj")])
(get-configs [nil (resources "config.clj") nil [nil nil]]))))
+
+(deftest test-middleware
+ (let [call-count (atom 0)
+ call-mdlware (fn [f]
+ (fn [cfg-map]
+ (swap! call-count inc)
+ (f cfg-map)))
+ empty-cfg (configurer (resources "config.clj"))
+ mdlware-cfg (configurer (resources "config.clj")
+ [call-mdlware])
+ cached-cfg (configurer (resources "config.clj")
+ [call-mdlware cache-config])
+ eval-cfg (configurer (resources "config.clj")
+ [eval-config])]
+ (testing "General middleware"
+ (is (= true (empty-cfg :from-test)))
+ (is (= 0 @call-count))
+ (is (= true (mdlware-cfg :from-test)))
+ (is (= 1 @call-count)))
+ (testing "Caching works"
+ (is (= true (cached-cfg :from-test)))
+ (is (= true (cached-cfg :from-test)))
+ (is (= 2 @call-count)))
+ (testing "Eval works"
+ (is (= '(+ 1 1) (empty-cfg :eval-cfg)))
+ (is (= 2 (eval-cfg :eval-cfg))))))

0 comments on commit 266a0cb

Please sign in to comment.