Skip to content

Commit

Permalink
core_dsl: disable Getwd() with environment variable (#1357)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevinburke committed Feb 12, 2024
1 parent 898cba9 commit cd418b7
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 94 deletions.
13 changes: 11 additions & 2 deletions core_dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func RunSpecs(t GinkgoTestingT, description string, args ...interface{}) bool {

err = global.Suite.BuildTree()
exitIfErr(err)
suitePath, err := os.Getwd()
suitePath, err := getwd()
exitIfErr(err)
suitePath, err = filepath.Abs(suitePath)
exitIfErr(err)
Expand Down Expand Up @@ -345,6 +345,15 @@ func extractSuiteConfiguration(args []interface{}) Labels {
return suiteLabels
}

func getwd() (string, error) {
if !strings.EqualFold(os.Getenv("GINKGO_PRESERVE_CACHE"), "true") {
// Getwd calls os.Getenv("PWD"), which breaks test caching if the cache
// is shared between two different directories with the same test code.
return os.Getwd()
}
return "", nil
}

/*
PreviewSpecs walks the testing tree and produces a report without actually invoking the specs.
See http://onsi.github.io/ginkgo/#previewing-specs for more information.
Expand All @@ -369,7 +378,7 @@ func PreviewSpecs(description string, args ...any) Report {

err = global.Suite.BuildTree()
exitIfErr(err)
suitePath, err := os.Getwd()
suitePath, err := getwd()
exitIfErr(err)
suitePath, err = filepath.Abs(suitePath)
exitIfErr(err)
Expand Down

0 comments on commit cd418b7

Please sign in to comment.