Fork me on GitHub

hi, i’m using luminus with datomic. For my tests, i’d like to just create an in-mem db, but basically create a fresh one for each test invocation. I’m not really sure how to manage this with mount, etc since when i require one of my namespaces, mount will have already wired in the connection


I’ve looked at and the mount docs, but I’m not quite ‘getting’ how i’d have my tests, start only the db stuff, for each test



(mount/start-with {#'app.db/datomic in-memory-db})


yeah i looked at that. So, i’d like do a start-with in a fixture perhaps?


@eoliphant What I usually do (regardless of mount or component) is to have a function, that does that setup, executes the test and does the teardown. Just like with junit or friends. In clojure.test you will have to use the fixtures for that.


hi sveri, yeah I thoughgt about that too. But then it get’s a little weird because when I want to test some ‘database functions’ and say myapp.dbfuncs is pulling in myapp.db.core, mount is doing the autowiring magic and makes say ‘conn’ available in that namespace. I’m not seeing how I can ‘inject’ ‘conn’ for a test, without using something like mount/start-with


@eoliphant right. one of the reasons mount/start-with exists is to help with testing (i.e. swapping / mocking / stubbing)


yeah, I guess one thing that’s not clear yet (I’m relatively new to clojure and its ecosystem), is where to ‘hook’ this. Like when I look at the tests that were created by the template (using the api/swagger profile), say app, I think isn’t depending on ‘mounted’ state? So it might not be a good example?


also, now that I think about it… hmm… if i’m using say the ‘mem’ datomic uri in my profile. Then that part is fine, as is, I think. But I still need a fresh one for each test. wondering if that would be I dunno, just starting and stopping the state, as it is for each test?


depending on how you test things. if you need states in your test, I would start and stop them for each to isolate tests from each other. but you can also start stop them in fixtures :before-all, :after-all.. depending on what testing framework you are using.


ok that makes sense. Just for my understanding though. If I’m using a namespace that say pulls in my datomic ‘conn’ via the .db.core then uses that ‘conn’ as a namespace global there’s really no other way for me to say ‘inject’ a ‘conn’ than using the mount stuff ?


like I have the following

  (:require [datomic.api :as d]
            [gs-authorization.db.core :refer [conn]]
            [clojure.walk :as walk]
(defn my-func-to-test [] . (use-conn conn))


when I use (my-func-to-test) in my app somewhere, mount is magically making sure that conn is initialized. But in a (deftest …. (my-func-to-test..)) this is where I want to say plug in my own conn, or just make sure I get a fresh one per test


mount is managing these states, hence it is logical that "pluging in" can be via mount (i.e. start-with)