diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2026-04-15 22:37:59 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <brad@danga.com> | 2026-04-15 15:44:19 -0700 |
| commit | b39ee0445d1e7b1f7fda57caa0f387c42ddd1db6 (patch) | |
| tree | 808d23c9ee896caaf4c357a9386529a73db77f73 | |
| parent | eea39eaf52001ece2fd71a7f10079c3b2687a85b (diff) | |
| download | tailscale-b39ee0445d1e7b1f7fda57caa0f387c42ddd1db6.tar.xz tailscale-b39ee0445d1e7b1f7fda57caa0f387c42ddd1db6.zip | |
util/httpm: open .git/index to defeat Go test caching
TestUsedConsistently shells out to git grep to find forbidden
http.Method* uses across the repo. Since the test itself doesn't
open any repo files, Go's test cache considers it unchanged
between commits and serves stale passing results even when new
violations are introduced.
Fix by opening .git/index, which makes Go's test cache track it
as an input. The index file changes on git reset, checkout, pull,
etc., so the cache is properly invalidated when moving between
commits.
Updates tailscale/corp#40359
Change-Id: If1497b992a545351bdd68cff279d60f5591fe70b
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
| -rw-r--r-- | util/httpm/httpm_test.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/util/httpm/httpm_test.go b/util/httpm/httpm_test.go index 4a36a38e1..e8342a74f 100644 --- a/util/httpm/httpm_test.go +++ b/util/httpm/httpm_test.go @@ -24,6 +24,13 @@ func TestUsedConsistently(t *testing.T) { t.Skipf("skipping test since .git doesn't exist: %v", err) } + // Open .git/index so Go's test cache tracks it as an input. + // The index file changes on git reset, checkout, pull, etc., + // so the cache is properly invalidated when moving between commits. + if f, err := os.Open(filepath.Join(rootDir, ".git", "index")); err == nil { + f.Close() + } + cmd := exec.Command("git", "grep", "-l", "-F", "http.Method") cmd.Dir = rootDir matches, _ := cmd.Output() |
