diff --git a/src/carica/middleware.clj b/src/carica/middleware.clj index 36933d4..8b552ac 100644 --- a/src/carica/middleware.clj +++ b/src/carica/middleware.clj @@ -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)))))) diff --git a/test/carica/test/middleware.clj b/test/carica/test/middleware.clj index 13f74e7..4d36420 100644 --- a/test/carica/test/middleware.clj +++ b/test/carica/test/middleware.clj @@ -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) @@ -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.")))))