weavejester / environ

Library for managing environment variables in Clojure
922 stars 71 forks source link

boot-environ/environ weird precedence #65

Open st opened 7 years ago

st commented 7 years ago

In a new project, let's create this task:

(deftask run-tests
  []
  (comp
    (environ :env {:config-path "path-test.edn"})
    (test)))

and add this test

(deftest environ-precendence  
  (is (= "path-test.edn" (environ/env :config-path))))

It works fine until environment variable CONFIG_PATH is declared.

$ export CONFIG_PATH=path-prod
...
FAIL in (environ-precendence) (core_test.clj:8)
expected: "path-test.edn"
  actual: "path-prod"
    diff: - "path-test.edn"
          + "path-prod"

Shouldn't binding in deftask (environ :env {:config-path "path-test.edn"}) have precedence over environment variable?

weavejester commented 7 years ago

It should have precedence. The code performs a (merge environ/env env), so the environment argument should take precedence. If it's not, something is going weirdly wrong.

st commented 7 years ago

Hi, thanks for quick answer. Looking at the code, I came to the same conclusion (if merge is not broken ;-) )

Here is a tiny project to show/reproduce this issue: https://github.com/st/precedence (especially https://github.com/st/precedence/blob/master/test/precedence/core_test.clj)

Keep in mind there may be something I misunderstood.