TestTsgoRevInCacheKey verifies that the Tailscale Go toolchain's git revision (from go.toolchain.rev) is blended into Go build cache keys. Without this, bumping the toolchain to a new commit that doesn't change the Go version number would silently reuse stale cached build artifacts. See https://git
(t *testing.T)
| 19 | // |
| 20 | // See https://github.com/tailscale/tailscale/issues/36589. |
| 21 | func TestTsgoRevInCacheKey(t *testing.T) { |
| 22 | goRoot := goEnv(t, "GOROOT") |
| 23 | isTsgo := strings.Contains(goRoot, "/.cache/tsgo/") |
| 24 | if !cibuild.OnTailscaleCI() && !isTsgo { |
| 25 | t.Skip("skipping; not in Tailscale CI and not using the Tailscale Go toolchain") |
| 26 | } |
| 27 | |
| 28 | rev := strings.TrimSpace(GoToolchainRev) |
| 29 | if rev == "" { |
| 30 | t.Fatal("go.toolchain.rev is empty") |
| 31 | } |
| 32 | |
| 33 | // Build the small stdlib "errors" package with GODEBUG=gocachehash=1, |
| 34 | // which causes cmd/go to log its cache key computations to stderr. |
| 35 | cmd := exec.Command("go", "build", "errors") |
| 36 | cmd.Env = append(os.Environ(), "GODEBUG=gocachehash=1") |
| 37 | out, err := cmd.CombinedOutput() |
| 38 | if err != nil { |
| 39 | t.Fatalf("go build errors failed: %v\n%s", err, out) |
| 40 | } |
| 41 | |
| 42 | // The cache key output should contain the toolchain rev alongside the |
| 43 | // Go version, e.g.: |
| 44 | // HASH[moduleIndex]: "go1.26.2 dfe2a5fd8ee2e68b08ce5ff259269f50ecadf2f4" |
| 45 | if !strings.Contains(string(out), rev) { |
| 46 | t.Errorf("go.toolchain.rev %q not found in GODEBUG=gocachehash=1 output:\n%s", rev, out) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func goEnv(t *testing.T, key string) string { |
| 51 | t.Helper() |
nothing calls this directly
no test coverage detected
searching dependent graphs…