This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-30
Channels
- # adventofcode (4)
- # aleph (1)
- # announcements (6)
- # babashka (11)
- # beginners (63)
- # calva (73)
- # clj-kondo (9)
- # clj-on-windows (20)
- # cljdoc (8)
- # cljsrn (4)
- # clojure (48)
- # clojure-europe (20)
- # clojure-italy (1)
- # clojure-nl (11)
- # clojure-spec (11)
- # clojure-uk (3)
- # clojurescript (32)
- # cloverage (1)
- # conjure (1)
- # cryogen (5)
- # datomic (83)
- # fulcro (28)
- # graphql (23)
- # gratitude (4)
- # helix (15)
- # honeysql (4)
- # improve-getting-started (14)
- # introduce-yourself (3)
- # jackdaw (5)
- # kaocha (11)
- # leiningen (1)
- # malli (1)
- # meander (5)
- # off-topic (18)
- # pathom (17)
- # pedestal (6)
- # polylith (15)
- # practicalli (1)
- # quil (2)
- # reitit (4)
- # releases (6)
- # shadow-cljs (38)
- # sql (20)
- # testing (6)
- # timbre (5)
- # tools-deps (11)
- # vim (2)
@josephson.victor what I usually do is use two env vars - one for tests, and one for production/dev code.
@U3Y18N0UC do you then have to modify your source code to point to the right env var each time you switch between running tests or running a local/dev environment?
Not really, you just have to inject dependencies. For example, instead of defining a "global db pool" you can create a "generate-pool" function that will receive the arguments and return a db pool.
In your main app, you just use (let [db-conn (generate-pool <db-env>)] (start-the-app! db-conn))
And in your test file, you do the (let [db-conn (generate-pool <test-db-env>)] (start-the-app! db-conn))
great, thanks for those suggestions:) For my current code base it was easiest to use jvm-opts in my :test alias per @U04V70XH6’s suggestion, but I’ll play around with your solution too. Always good to learn multiple ways of doing things
ℹ️ If anyone is running tests with/on GitHub Actions, FYI, GitHub’s https://github.com/actions/setup-java#caching-packages-dependencies “action” https://github.blog/changelog/2021-08-30-github-actions-setup-java-now-supports-dependency-caching/ dependency caching via Maven. This might work for Clojure projects — at least, I hope it will, even if it requires a little tinkering.