Skip to content

Commit cd418b7

Browse files
authored
core_dsl: disable Getwd() with environment variable (#1357)
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. Fixes #1355.
1 parent 898cba9 commit cd418b7

File tree

2 files changed

+114
-94
lines changed

2 files changed

+114
-94
lines changed

core_dsl.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func RunSpecs(t GinkgoTestingT, description string, args ...interface{}) bool {
292292

293293
err = global.Suite.BuildTree()
294294
exitIfErr(err)
295-
suitePath, err := os.Getwd()
295+
suitePath, err := getwd()
296296
exitIfErr(err)
297297
suitePath, err = filepath.Abs(suitePath)
298298
exitIfErr(err)
@@ -345,6 +345,15 @@ func extractSuiteConfiguration(args []interface{}) Labels {
345345
return suiteLabels
346346
}
347347

348+
func getwd() (string, error) {
349+
if !strings.EqualFold(os.Getenv("GINKGO_PRESERVE_CACHE"), "true") {
350+
// Getwd calls os.Getenv("PWD"), which breaks test caching if the cache
351+
// is shared between two different directories with the same test code.
352+
return os.Getwd()
353+
}
354+
return "", nil
355+
}
356+
348357
/*
349358
PreviewSpecs walks the testing tree and produces a report without actually invoking the specs.
350359
See http://onsi.github.io/ginkgo/#previewing-specs for more information.
@@ -369,7 +378,7 @@ func PreviewSpecs(description string, args ...any) Report {
369378

370379
err = global.Suite.BuildTree()
371380
exitIfErr(err)
372-
suitePath, err := os.Getwd()
381+
suitePath, err := getwd()
373382
exitIfErr(err)
374383
suitePath, err = filepath.Abs(suitePath)
375384
exitIfErr(err)

0 commit comments

Comments
 (0)