[#817] add crispin to lib tests and projects.md (#918)

* add crispin to lib tests and projects.md

* add a missing line in crispin example
This commit is contained in:
Bob 2021-07-07 04:01:36 -04:00 committed by GitHub
parent 4c0578c56c
commit b53be25b94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 1 deletions

View file

@ -81,7 +81,8 @@
rm-hull/jasentaa {:mvn/version "0.2.5"}
slingshot/slingshot {:mvn/version "0.12.2"}
io.replikativ/hasch {:mvn/version "0.3.7"}
com.grammarly/omniconf {:mvn/version "0.4.3"}}
com.grammarly/omniconf {:mvn/version "0.4.3"}
crispin/crispin {:mvn/version "0.3.8"}}
:classpath-overrides {org.clojure/clojure nil
org.clojure/spec.alpha nil
org.clojure/core.specs.alpha nil}}

View file

@ -40,6 +40,9 @@ The following libraries and projects are known to work with babashka.
- [rewrite-edn](#rewrite-edn)
- [expound](#expound)
- [omniconf](#omniconf)
- [slingshot](#slingshot)
- [hasch](#hasch)
- [crispin](#crispin)
- [Pods](#pods)
- [Projects](#projects-1)
- [babashka-test-action](#babashka-test-action)
@ -598,6 +601,33 @@ NOTE: hasch's tests pass with babashka except the test around hashing
records. This is due to a difference in how records are implemented in
babashka. This may be fixed later if this turns out to be really useful.
### [crispin](https://github.com/dunaj-project/crispin)
Populate a configuration map from multiple sources (environment variables,
system variables, config files, etc.)
Example:
script.clj
``` clojure
#!/usr/bin/env bb
(ns script
(:require [babashka.deps :as deps]))
(deps/add-deps
'{:deps {crispin/crispin {:mvn/version "0.3.8"}}})
(require '[crispin.core :as crispin])
(def app-cfg (crispin/cfg))
(app-cfg :foo)
```
``` text
FOO=1 script.clj
"1"
```
## Pods
[Babashka pods](https://github.com/babashka/babashka.pods) are programs that can

View file

@ -223,6 +223,8 @@
(test-namespaces 'omniconf.core-test)
(test-namespaces 'crispin.core-test)
;;;; final exit code
(let [{:keys [:test :fail :error] :as m} @status]

View file

@ -0,0 +1,22 @@
(ns crispin.core-test
(:require [clojure.test :refer [deftest is testing]]
[crispin.core :as cfg]))
(deftest crispin.core-test
(testing "config from multiple sources"
(do
(cfg/load-custom-cfg! "test-resources/lib_tests/crispin" "crispin-test-custom-cfg.edn")
(System/setProperty "crispintest.value" "yes")
(System/setProperty "crispin" "test-resources/lib_tests/crispin/crispin-test-cfg.edn")
(let [c (cfg/cfg)]
; something from the environment
(is (not-empty (cfg/sget c :path)))
; things from the resource named by the :crispin property
(is (= "pina colada" (cfg/sget-in c [:likes 0])))
(is (= 3.14 (cfg/nget-in c [:crispintest :pi])))
; something from system properties
(is (true? (cfg/bget-in c [:crispintest :value])))
; something from load-custom-cfg! file
(is (= :bar (:foo c))))
(System/clearProperty "crispintest.value")
(System/clearProperty "crispin"))))

View file

@ -0,0 +1,2 @@
{:crispintest {:pi 3.14}
:likes ["pina colada" "getting caught in the rain"]}

View file

@ -0,0 +1 @@
{:foo :bar}