MCPcopy Index your code
hub / github.com/tailscale/tailscale / TestTsgoRevInCacheKey

Function TestTsgoRevInCacheKey

cache_key_test.go:21–48  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

19//
20// See https://github.com/tailscale/tailscale/issues/36589.
21func 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
50func goEnv(t *testing.T, key string) string {
51 t.Helper()

Callers

nothing calls this directly

Calls 9

OnTailscaleCIFunction · 0.92
goEnvFunction · 0.85
EnvironMethod · 0.80
CombinedOutputMethod · 0.80
SkipMethod · 0.65
FatalMethod · 0.65
FatalfMethod · 0.65
ErrorfMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…