dnephin/pre-commit-golang

could not pass environment variables to go-unit-tests

bilalcaliskan opened this issue · 2 comments

Currently, i have a project which gets the application configuration from remote config server on production, and gets the local configuration file while unit testing. In order to decide when we are on production or local environment, i use the below environment variable:

ACTIVE_PROFILE=unit-test

But if i run the go-unit-tests hook, it tries to fetch the configuration from remote config server as you guess. I have googled it but i could not find anything useful, is it possible to pass environment variable to go-unit-tests hook or would not be nice if we could define it like below?

- id: go-unit-tests
  args: [-e="ACTIVE_PROFILE=unit-test"]

I'm not sure, but this seems like it would need to be supported by pre-commit not just these hooks. If you set that environment variable in the shell, does it not get inherited by the hooks? Maybe you could add it to the .git/hooks/pre-commit script that runs pre-commit ?

@dnephin as you suggested, i have added the below lines in .git/hooks/pre-commit and it works perfectly, thanks for advice!

# custom variable definition for local development
os.environ["CONFIG_PATH"] = "./"
os.environ["ACTIVE_PROFILE"] = "unit-test"