#47 composition tests are in

This commit is contained in:
Anatoly 2016-01-31 23:54:47 -05:00 committed by anatoly
parent c2828cc3dc
commit 926e4a9d2a
2 changed files with 46 additions and 2 deletions

View file

@ -4,6 +4,7 @@
[clojure.set :refer [intersection]]
[clojure.string :as s])
:cljs (:require [mount.tools.macro :as macro]
[clojure.set :refer [intersection]]
[mount.tools.logger :refer [log]]))
#?(:cljs (:require-macros [mount.core]
[mount.tools.macro :refer [if-clj on-error throw-runtime]])))
@ -239,8 +240,10 @@
(remove (comp :sub? @meta-state) (find-all-states)))
(defn start [& states]
(let [states (or (seq states) (all-without-subs))]
{:started (bring states up <)}))
(if (-> states first coll?)
(apply start (first states))
(let [states (or (seq states) (all-without-subs))]
{:started (bring states up <)})))
(defn stop [& states]
(let [states (or states (find-all-states))

View file

@ -114,3 +114,44 @@
(is (= 42 (dval test-conn))) ;; test-conn is explicitly started via "t-states"
(mount/stop)))))
#?(:clj
(deftest composing
(testing "states provided to the top level should narrow down the scope for the whole composition"
(let [scope [#'tapp.conf/config
#'tapp.example/nrepl
#'tapp.nyse/conn
#'mount.test.composable-fns/test-nrepl
#'mount.test.composable-fns/test-conn]
states (-> (only scope)
(with-args {:a 42})
(except [#'mount.test.composable-fns/test-nrepl
#'mount.test.composable-fns/test-conn])
(swap-states {#'tapp.example/nrepl #'mount.test.composable-fns/test-nrepl})
(swap {#'tapp.conf/config {:datomic {:uri "datomic:mem://composable-mount"}}}))]
(is (= #{"#'tapp.nyse/conn" "#'tapp.conf/config" "#'tapp.example/nrepl"} (set states)))
(mount/start states)
(is (= {:a 42} (mount/args)))
(is (= {:datomic {:uri "datomic:mem://composable-mount"}} (dval config)))
(is (instance? datomic.peer.LocalConnection (dval conn)))
(is (vector? (dval nrepl)))
(mount/stop)))
(testing "should compose and start in a single composition"
(let [scope [#'tapp.conf/config
#'tapp.example/nrepl
#'tapp.nyse/conn
#'mount.test.composable-fns/test-nrepl
#'mount.test.composable-fns/test-conn]]
(-> (only scope)
(with-args {:a 42})
(except [#'mount.test.composable-fns/test-nrepl
#'mount.test.composable-fns/test-conn])
(swap-states {#'tapp.example/nrepl #'mount.test.composable-fns/test-nrepl})
(swap {#'tapp.conf/config {:datomic {:uri "datomic:mem://composable-mount"}}})
mount/start)
(is (= {:a 42} (mount/args)))
(is (= {:datomic {:uri "datomic:mem://composable-mount"}} (dval config)))
(is (instance? datomic.peer.LocalConnection (dval conn)))
(is (vector? (dval nrepl)))
(mount/stop)))))