Fork me on GitHub
#leiningen
<
2018-09-20
>
jumar15:09:11

We have some integration tests that use configuration from the :test profile. Now I want to run these tests from the REPL (Cider). What's a reasonable way to do it? Ideally, I'd run a single REPL and use :test config values only for tests but I guess there's no easy way how to do it.

mikerod15:09:47

@jumar I don’t completely understand the question I think.

mikerod15:09:00

What sort of config is in the :test profile?

jumar15:09:23

All sorts of things, mostly 3rd party credentials and database connection config. For me the db connection config is the critical thing I would say - because tests delete all data before they are run.

jumar15:09:59

the tests are intended to use different "test" database

mikerod15:09:03

How are you specifying the config though?

mikerod15:09:12

I wouldn’t think it’s just arbitrary format in the :test profile

mikerod15:09:15

are you using a config lib or something?

jumar15:09:50

We have these config keys in profiles.clj and use environ to read keys from env

mikerod15:09:28

So you should be able to read the environ information in the REPL as well

mikerod15:09:59

and it will give you either the env variable, sys property, or whatever is in lein

mikerod15:09:07

the :test profile info should be available in a typical lein repl

jumar15:09:43

Right, but I think I'll get only the config values associated with active profile which normally, in my case, is :dev. So I guess I need to run another REPL with the :test profile, right?

jumar15:09:27

The problem is that we have the same keys (e.g. db connection string) in both profiles and they have different values depending on which profile is active (`:dev` or :test). I'm just curious what people usually do in this situation.

mikerod15:09:13

I think you’d have :dev and :test both active

mikerod15:09:19

one just merges over the other

jumar15:09:30

No, that's not the case - in my case, :test is run only for lein test (https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md#task-specific-profiles)

mikerod15:09:45

oh, :test isn’t a default woops

mikerod15:09:53

[:base :system :user :provided :dev] defaults

mikerod15:09:58

and for repl, so is :repl

jumar15:09:05

But the resource I linked mentions this :-D > Please note that putting things in the :test profile is strongly advised against as it can result in tests which can't be run from the repl.

mikerod15:09:28

but I’m not sure what you want to do in your case: you want the lein repl to have visibility into both values for the config at the same time?

mikerod15:09:46

I’d think you’d just have a single source of this in :dev

jumar15:09:23

Yeah, I'm really not sure. I guess I cannot expect both profiles to work at the same time. I'll need to think how to configure my tests so that they use different database and are still runnable from the REPL

mikerod15:09:15

if you used a different config lib, like say juxt/aero, you can have the various config under :profiles

mikerod15:09:29

and you can just use juxt/aero fn to load the config for the profile you want from the repl

mikerod15:09:41

but then again, that is changing more stuff and you may be happy with environ

jumar15:09:58

Oh, great. I guess, I won't be able to change config lib now, but that's good to know. Thanks!