Fork me on GitHub
#duct
<
2020-08-17
>
plins20:08:23

hello everyone, I see that version 0.8.0 introduced `:duct.profile/test` but I dont see any mention on how to use it, what it enables me to do ? ideally id like to create a test.edn somewhere and I when ran lein test that config gets merged with the dev one. Is there something like that already implemented or ill need to write a fixture of my own, parse both edn files, merge then, then use ig/init passing that configuration?

Kevin20:08:36

if you are you're initiating the configuration in your fixture you can add the :duct.profile/test key to the initializing function

plins20:08:07

not sure if I got you, a little bit more context: I was using 0.7.0, upgraded to 0.8.0, what I need to modify for it to work?

plins20:08:24

(duct noob here)

Kevin20:08:03

You could use integrant.repl to manage it for you in the tests.

(defn- read-config []
  (duct/read-config (io/resource "my-app/config.edn")))

(defn init-system []
  (duct/load-hierarchy)
  (integrant.repl/set-prep! #(duct/prep-config (read-config) [:duct.profile/test])) ;; <<<<< TEST PROFILE GOES HERE
  (integrant.repl/go))

(defn halt-system []
  (integrant.repl/halt))
(defn once-fixture [tests]
  (init-system)
  (tests)
  (halt-system))

(use-fixtures :once once-fixture)

plins20:08:48

@UG9U7TPDZ just out of curiosity, why not use ig/init and ig/halt! ?

plins20:08:19

it seems a bit strange to me to use code designed to be used in the repl in a test configuration, thats why I ask

Kevin20:08:09

You can also do that. But you'll have to keep track of the state yourself in order to halt the system. Which is also fine

plins20:08:50

fair point!

plins20:08:17

what would you do? an atom?

Kevin20:08:11

Yes, I'd use an atom

plins20:08:29

once again, thanks 🙂

Kevin20:08:29

That would merge the test profile into your main config.edn

plins20:08:54

thanks 🙂