Fork me on GitHub
#mount
<
2020-05-29
>
Matti Uusitalo07:05:44

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.

Matti Uusitalo07:05:08

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

Matti Uusitalo10:05:13

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

Matti Uusitalo10:05:04

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

tolitius13:05:26

* 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