diff --git a/src/immuconf/config.clj b/src/immuconf/config.clj index 998150d..79eea31 100644 --- a/src/immuconf/config.clj +++ b/src/immuconf/config.clj @@ -3,6 +3,7 @@ (:require [clojure.walk :as w] [clojure.edn :as edn] [clojure.string :as s] + [clojure.java.io :as java.io] [clojure.tools.logging :as log])) (ns-unmap *ns* 'Override) @@ -75,7 +76,9 @@ given filename and the resulting config " [file] (try - [file (edn/read-string {:readers *data-readers*} (slurp file))] + (let [file-as-file (java.io/as-file file)] + (when (.exists file-as-file) + [file (edn/read-string {:readers *data-readers*} (slurp file-as-file))])) (catch Throwable t (throw (ex-info (format "Error loading config file: %s" file) {:file file} t))))) diff --git a/test/immuconf/config_test.clj b/test/immuconf/config_test.clj index 27b3130..3f3ecdd 100644 --- a/test/immuconf/config_test.clj +++ b/test/immuconf/config_test.clj @@ -51,6 +51,15 @@ (System/setProperty "user.home" (str (System/getProperty "user.dir") "/test")) (is (cfg/load "~/fixtures/test-a.edn"))) +(deftest missing-files-are-allowed + (is (= (cfg/load "test/fixtures/test-a.edn" + "test/fixtures/this-file-does-not-exist.edn" + "test/fixtures/test-b.edn") + {:a {:b {:c 1 :d 2}}}) + "Missing files are treated as empty maps") + (is (= {} (cfg/load "test/fixtures/this-file-does-not-exist.edn" + "test/fixtures/another-missing-file.edn")) + "If all files are missing, the config is an empty map"))