onsi / ginkgo

A Modern Testing Framework for Go
http://onsi.github.io/ginkgo/
MIT License
8.29k stars 654 forks source link

Getwd() breaks test caching on build runners like Buildkite #1355

Closed kevinburke closed 7 months ago

kevinburke commented 7 months ago

I work on a project that has a test suite that calls ginkgo.RunSpecs. RunSpecs calls os.Getwd() in order to set the SuitePath, which is used mainly for cosmetic purposes - the display in the default reporter.

Unfortunately os.Getwd() calls os.Getenv("PWD"), which can change from run to run if you are using a test suite runner like e.g. Buildkite. Because test caching relies on environment variables being the same from run to run, this facile change breaks test caching.

It would be great if there was an option to disable the os.Getwd() call, so we can preserve test caching, otherwise we may try to pivot away from using this library altogether.

onsi commented 7 months ago

hey there - happy to add this, perhaps configured via the presence of an environment variable like GINKGO_PRESERVE_CACHE=TRUE or some-such. I see you've already started a fork to validate getting rid of that os.Getcwd() call would be sufficient? Would you be up for adding a guard based on that environment variable and validating that you get the behavior you want?