#47 composition tests are in
This commit is contained in:
parent
c2828cc3dc
commit
926e4a9d2a
2 changed files with 46 additions and 2 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
[clojure.set :refer [intersection]]
|
[clojure.set :refer [intersection]]
|
||||||
[clojure.string :as s])
|
[clojure.string :as s])
|
||||||
:cljs (:require [mount.tools.macro :as macro]
|
:cljs (:require [mount.tools.macro :as macro]
|
||||||
|
[clojure.set :refer [intersection]]
|
||||||
[mount.tools.logger :refer [log]]))
|
[mount.tools.logger :refer [log]]))
|
||||||
#?(:cljs (:require-macros [mount.core]
|
#?(:cljs (:require-macros [mount.core]
|
||||||
[mount.tools.macro :refer [if-clj on-error throw-runtime]])))
|
[mount.tools.macro :refer [if-clj on-error throw-runtime]])))
|
||||||
|
|
@ -239,8 +240,10 @@
|
||||||
(remove (comp :sub? @meta-state) (find-all-states)))
|
(remove (comp :sub? @meta-state) (find-all-states)))
|
||||||
|
|
||||||
(defn start [& states]
|
(defn start [& states]
|
||||||
|
(if (-> states first coll?)
|
||||||
|
(apply start (first states))
|
||||||
(let [states (or (seq states) (all-without-subs))]
|
(let [states (or (seq states) (all-without-subs))]
|
||||||
{:started (bring states up <)}))
|
{:started (bring states up <)})))
|
||||||
|
|
||||||
(defn stop [& states]
|
(defn stop [& states]
|
||||||
(let [states (or states (find-all-states))
|
(let [states (or states (find-all-states))
|
||||||
|
|
|
||||||
|
|
@ -114,3 +114,44 @@
|
||||||
(is (= 42 (dval test-conn))) ;; test-conn is explicitly started via "t-states"
|
(is (= 42 (dval test-conn))) ;; test-conn is explicitly started via "t-states"
|
||||||
(mount/stop)))))
|
(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)))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue