Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO_ENV not set to "test" because golang test environment not yet initialized #16

Closed
armhold opened this issue Oct 10, 2018 · 1 comment

Comments

@armhold
Copy link
Contributor

armhold commented Oct 10, 2018

I had some test failures in my buffalo app that I traced back to the following problem: I was running go test ./actions/ manually rather than using buffalo test. GO_ENV was being automatically set to development inside my app, rather than test, causing a lot of confusion.

It looks like envy tries to detect the presence of the golang test environment, and if present, sets GO_ENV to test if otherwise undefined.

However this only works if the testing package has already been loaded by go before envy's init() func gets run. I don't think we can count on the order of package initialization if there is no explicit dependency between them. I've created a gist that demonstrates this.

In my own non-buffalo projects I have run into this general problem of how to detect when running in a unit test and setting the environment appropriately. I haven't come up with a good solution.

armhold added a commit to armhold/envy that referenced this issue Oct 11, 2018
@armhold
Copy link
Contributor Author

armhold commented Oct 11, 2018

Clarification: the problem seems to come from envy expecting:

  1. go test is run with "-v"
  2. the test binary has already invoked flag.Parse() by the time that envy.init() is run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant