In my Clojure project, I'm using a namespace for storing configuration:
(ns clojure-bgproc.settings
(:require [environ.core :refer [env]]
[clojure.edn :as edn]))
(def ^:dynamic *app-env* (env :app-env "production"))
(def ^:private config-path
(if (= *app-env* "test") "settings_test.edn" "settings.edn"))
(def config (-> config-path slurp edn/read-string))
(def db-config (:db config))
For test environment, I use a fixture to redefine *app-env*
:
(ns helpers.config
(:require [clojure-bgproc.settings :refer :all]))
(defn with-test-config [f]
(with-redefs [*app-env* "test"]
(f)))
And while the *app-env*
is redefined, all the other config variables are not:
FAIL in (app-config-test) (core_test.clj:14)
expected: (s/ends-with? (:dbname db-config) "test")
actual: (not (s/ends-with? "rmq-reports-development" "test"))
Is there a way for me to easily redefine all the other config variables without me having to manually recompute them?