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
5 changes: 4 additions & 1 deletion src/immuconf/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))))
Expand Down
9 changes: 9 additions & 0 deletions test/immuconf/config_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"))