我有一个Leiningen Clojure项目,在project.clj
中指定了一个Postgres数据库,如下:
:profiles {:test {:env {:db-address "//non-standard/location" ...} ...} ...}
现在我正在尝试在一个数据库位于标准位置的机器上运行我的测试,但我无法找到一种尊重该位置运行测试的方法。
我已经添加了一个额外的配置文件条目:
:other {:env {:db-address "//standard/location"}}}
...然后运行lein with-profile other test
,认为只有:db-address
条目会覆盖:test
中的条目,但我仍然得到连接被拒绝(Connection refused)
。
我已经完全复制了:test
条目并将:db-address
条目更改为:other
,但无论我是运行lein with-profile other test
还是lein with-profile +other test
都没有任何效果。
如果我完全删除:test
档案,则leiningen会完全失败,尽管文档说lein with-profile other test
应该忽略其他档案。
我几乎被卡住了。如果在运行lein
之前在project.clj
中以文本方式替换非标准位置为标准位置,我可以运行测试,但我希望有一些更官方和不那么hacky的方法。任何帮助将不胜感激。
编辑添加:
我尝试使用^:replace
标签的两种方式。
:other {:env {:db-address ^:replace "//standard/location" } }
这会导致一个错误:Metadata 只能应用于 IMetas。
:other {:env ^:replace { ... map copied from :test profile ... } }
这会导致一个错误:java.io.FileNotFoundException: Could not locate ring/mock/request__init.class or ring/mock/request.clj on classpath: , compiling [...]
。所以显然在这种情况下我的CLASSPATH被清空了?令人困惑。
进一步编辑添加:
刚才出现的“空类路径”错误显然是由于我没有将:test
配置文件中的:dependencies
参数带到:other
配置文件中。
:other
配置文件中使用^replace
像这样:db-address ^:replace "//some-location"
或者在整个:env
键上更好。您在启动时打印调试:db-address
的值了吗?您有一个名为 DB_ADDRESS 的环境变量,是否可以覆盖项目.clj中的变量? - Kungitest
覆盖了other
。尝试 Kungi 的建议或者尝试这个:lein with-profile -test,+other test
。 - user21037lein with-profile +standard-test test
进行标准数据库位置的测试,而对于另一个位置则运行lein with-profile +other-test test
。此外,您可以为这两种情况创建别名,例如{:aliases {"test" ["with-profile" "+standard-test" "test"] "test-other" ["with-profile" "+other-test" "test"] } }
。 - user771505