Fork me on GitHub
#luminus
<
2017-01-31
>
eoliphant02:01:56

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

eoliphant02:01:55

I’ve looked at http://www.luminusweb.net/docs/components.md and the mount docs, but I’m not quite ‘getting’ how i’d have my tests, start only the db stuff, for each test

tolitius02:01:02

i.e.

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

eoliphant03:01:13

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

sveri08:01:29

@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.

eoliphant14:01:33

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

tolitius14:01:33

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

eoliphant15:01:49

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?

eoliphant15:01:23

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?

tolitius15:01:04

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.

eoliphant18:01:03

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 ?

eoliphant18:01:23

like I have the following

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

eoliphant18:01:10

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

tolitius20:01:10

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