Mock the fetching of environment variables for cleaner testings #7
Labels
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
It would be beneficial to have consistency in how you handle environmental overrides. Looking at TestCoalesceConfiguration_Model_CLIOverride, you're directly manipulating the environment variables within the test function. This is a bit risky because if the test were to fail before the defer statement is able to run, the environment could be left in an altered state.
Considering Go's practices, it's often better to abstract the environment variable accessors to enable easier mocking and to create a cleaner separation of concerns.
Here's a suggested approach using an interface to abstract environment variable access:
Using this, you can control your environment in a much safer way in your tests without the risk of affecting the global environment.
The text was updated successfully, but these errors were encountered: