Hi, my project connects to a postgres db using a simple (def db (jdbc/get-datasource (System/getenv "DATABASE_URL") in my db namespace. When running my tests, I want to set that env variable to point to my test db. What would be a recommended way to set that env variable when running my tests? Right now Iām just setting it on the command line: DATABASE_URL=<test-db-url> clj -M:test , but I would ideally like to have it in my deps.edn :test alias. Is that possible?
@josephson.victor No, you can't set environment variables after a process starts up.
You could use a JVM property instead, which you could set with :jvm-opts in your :test alias.
Or do something like (or (System/getProperty "database.url") (System/getenv "DATABASE_URL")) then you can override it via -Ddatabase.url=... in JVM opts but still use the env var when that property is not set.
Thanks so much, @seancorfield, you have no idea how much I appreciate your help and contributions in the Clojure community š