[#877] add omniconf lib tests
This commit is contained in:
parent
f47f8b9ad1
commit
097e45d180
3 changed files with 40 additions and 1 deletions
3
deps.edn
3
deps.edn
|
|
@ -80,7 +80,8 @@
|
|||
io.helins/binf {:mvn/version "1.1.0-beta0"}
|
||||
rm-hull/jasentaa {:mvn/version "0.2.5"}
|
||||
slingshot/slingshot {:mvn/version "0.12.2"}
|
||||
io.replikativ/hasch {:mvn/version "0.3.7"}}
|
||||
io.replikativ/hasch {:mvn/version "0.3.7"}
|
||||
com.grammarly/omniconf {:mvn/version "0.4.3"}}
|
||||
:classpath-overrides {org.clojure/clojure nil
|
||||
org.clojure/spec.alpha nil
|
||||
org.clojure/core.specs.alpha nil}}
|
||||
|
|
|
|||
|
|
@ -221,6 +221,8 @@
|
|||
(test-namespaces 'hasch.test
|
||||
)
|
||||
|
||||
(test-namespaces 'omniconf.core-test)
|
||||
|
||||
;;;; final exit code
|
||||
|
||||
(let [{:keys [:test :fail :error] :as m} @status]
|
||||
|
|
|
|||
36
test-resources/lib_tests/omniconf/core_test.clj
Normal file
36
test-resources/lib_tests/omniconf/core_test.clj
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
(ns omniconf.core-test
|
||||
(:require [clojure.string :as str]
|
||||
[clojure.test :refer [deftest is testing]]
|
||||
[omniconf.core :as cfg])
|
||||
(:import (java.io File)))
|
||||
|
||||
(cfg/define
|
||||
{:conf {:type :file}
|
||||
:foo {:type :string
|
||||
:required true}
|
||||
:the-boolean {:type :boolean}
|
||||
:missing {:type :string
|
||||
:required true}})
|
||||
|
||||
(deftest load-cfg-test
|
||||
(testing "multiple config sources"
|
||||
(let [temp-cfg-file (File/createTempFile "cfg" "edn")
|
||||
_ (.deleteOnExit temp-cfg-file)
|
||||
fake-args ["--conf" (.getAbsolutePath temp-cfg-file)
|
||||
"--foo" "this will be overridden"]]
|
||||
(do
|
||||
; put some props in the temp file
|
||||
(spit temp-cfg-file "{:foo \"final value\" :the-boolean false }")
|
||||
; and set a system property
|
||||
(System/setProperty "the-boolean" "18")
|
||||
(cfg/populate-from-cmd fake-args)
|
||||
(cfg/populate-from-file (cfg/get :conf))
|
||||
(cfg/populate-from-properties)
|
||||
; cleanup
|
||||
(System/clearProperty "the-boolean")))
|
||||
(is (= "final value" (cfg/get :foo)))
|
||||
(is (= true (cfg/get :the-boolean)))
|
||||
(is (thrown-with-msg? Exception #":missing" (cfg/verify)))
|
||||
(cfg/populate-from-map {:missing "abc"})
|
||||
(let [verify-output (with-out-str (cfg/verify))]
|
||||
(is (every? #(str/includes? verify-output %) [":missing" "abc"])))))
|
||||
Loading…
Reference in a new issue