So I have a personal project with 2 types of tests: unit tests and integration tests. It is my personal believe this is a rather common scenario for people who value testing or where testing makes sense.
How I do it
I use the config folder to put all of the configurations and my folder looks like the following:
├── config/ │ ├── config.exs │ ├── dev.exs │ ├── prod.exs │ ├── integration.exs │ └── test.exs ├── lib/
Each file has configurations for the env they use.
In my code, I make use of such configurations like the following:
defmodule MarketManager.Store.FileSystem do @products_filename Application.compile_env!(:market_manager, :products) def get_products_from_syndicate(syndicate), do: @products_filename |> File.read!() |> Jason.decode!() |> find_syndicate(syndicate) # Rest of code... end
This way if I run a test, I can pass in
MIX_ENV=integration and it will fetch the values from
integration.exs for example.
The problem with this approach is that you either have to always prepend
MIX_ENV=blabla to your commands and it encourages you to have a more convoluted
mix.exs file if you want to avoid typing all the jargon before every command.
How do you do it?
I have seen some people in this forum mention they use a “Repo” file for this kind of thing, where they pass in dependencies. Others use a Settings file that is a wrapper for configuration.
How do you guys do it?