Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/carica/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@
(fn [f]
(fn [resources]
(let [cfg-map (f resources)]
(assoc-in cfg-map keyseq env-val))))))
(if-not (nil? env-val)
(assoc-in cfg-map keyseq env-val)
cfg-map))))))
13 changes: 10 additions & 3 deletions test/carica/test/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
(is (nil? (env-config :extra))))))))

(deftest test-env-substitute-config
(with-redefs [getenv (constantly "Now.")]
(testing "the envvar value is in the location"
(testing "the envvar value is in the location"
(with-redefs [getenv (constantly "Now.")]
(let [env-config (configurer
(resources "config.clj")
[(env-substitute-config "NOOP" :magic-word)
Expand All @@ -92,4 +92,11 @@
(is (= "Now." (env-config :magic-word))
"Should see our overridden value.")
(is (= "Now." (env-config :i-totally :dont-exist))
"Nested key paths should work, even if they aren't defined.")))))
"Nested key paths should work, even if they aren't defined."))))
(testing "a missing envvar returns the configured default"
(with-redefs [getenv (constantly nil)]
(let [env-config (configurer
(resources "config.clj")
[(env-substitute-config "NOOP" :magic-word)])]
(is (= "mellon" (env-config :magic-word))
"Should see our configured default value.")))))