kube-no-trouble
kube-no-trouble copied to clipboard
Testing and ENV variables
These are some notes on tests with Env variables, mostly discussed in context of #127, so not to forget:
Tests preferably should not rely on ENV variables, however, there are some, where we test functionality that is directly related to env variable (such as TestNewFromFlagsKubeconfigHome). In such cases it would be nice to:
-
Test should not rely on external environment, i.e. it should set/unset its variables at the beginning (i.e. should be self-contained)
-
Test should return the env to a previous state, i.e. no variables should be leaked (it should not just unset the var, but actually revert, also there's a diff between var being empty and unset(
-
Ideally, we keep in mind tests can be run in parallel -> i.e. in case tests happen to use same variable this should be accounted for, perhaps some locking mechanism might be needed.
- By default go does not run tests in the same file in parallel, unless
t.Parallel()
is called - However, tests in different packages are by default run in parallel
@dark0dave added some notes just not to forget ;)
- By default go does not run tests in the same file in parallel, unless
BIG :+1: from me!
Not stale - we should polish and move this info to some dev docs.