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.
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 usingbuffalo test
.GO_ENV
was being automatically set todevelopment
inside my app, rather thantest
, 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
totest
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.