mount

2020-05-29T07:14:44.014100Z

I’m struggling with making a test setup using mount state handling library. https://github.com/tolitius/mount#swapping-alternate-implementations I want to be able to: start my app in the repl test manually run clojure tests using a different database / schema continue testing manually after the tests Based on the documentation, I should be able to mount/start-with-states and then mount/stop would return the implementations to the original ones. Not so.

2020-05-29T07:17:08.014800Z

Furthermore, I don’t want to stop my dev time database connection during the tests.

2020-05-29T10:31:13.015200Z

so it looks like this has been a source of discussion earlier many times

2020-05-29T10:34:04.017100Z

I came up with something like this

(let [running-states (mount/running-states)]
      (when (seq running-states)
        (mount/stop))
      (mount/swap-states {#'env/config {:start read-test-config}})
      (mount/start-with-args {:config {:silent? true}})
      (run-tests)
      (mount/stop)
      (when (seq running-states)
         (mount/start (map symbol running-states))))
which 1. stops the currently running state 2. starts the application with config swapped out 3. runs the tests 4. stops the test states 5. starts any states that were running before the tests

tolitius 2020-05-29T13:31:23.017300Z

why not

tolitius 2020-05-29T13:31:26.017500Z

* start my app in the repl * test manually >> restart a database component with a different schema * run clojure tests using a different database / schema >> restart a database component ("normally") * continue testing manually after the tests