Skip to content

Commit

Permalink
Add antq.util.leiningen #109
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Nov 13, 2021
1 parent f29c6ba commit 0bb386e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/antq/util/leiningen.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(ns antq.util.leiningen
(:require
[clojure.string :as str]))

(defn- getenv
[x]
(System/getenv x))

(defn- env-name
"cf. https://github.com/technomancy/leiningen/blob/master/doc/DEPLOY.md#credentials-in-the-environment"
[kw]
(cond
(and (qualified-keyword? kw)
(= "env" (namespace kw)))
(str/upper-case (name kw))

(= :env kw)
"LEIN_PASSWORD"

:else
nil))

(defn env
[kw]
(some-> (env-name kw)
(getenv)))
12 changes: 12 additions & 0 deletions test/antq/util/leiningen_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns antq.util.leiningen-test
(:require
[antq.util.leiningen :as sut]
[clojure.test :as t]))

(t/deftest env-test
(with-redefs [sut/getenv identity]
(t/is (= "LEIN_PASSWORD" (sut/env :env)))
(t/is (= "FOO" (sut/env :env/foo)))
(t/is (= "FOO_BAR" (sut/env :env/foo_bar)))
(t/is (= nil (sut/env :invalid/foo_bar)))
(t/is (= nil (sut/env "string")))))

0 comments on commit 0bb386e

Please sign in to comment.