MCPcopy
hub / github.com/tailscale/tailscale / TestGoVersion

Function TestGoVersion

version_test.go:31–57  ·  view source on GitHub ↗

TestGoVersion tests that the Go version specified in go.mod matches ./tool/go version.

(t *testing.T)

Source from the content-addressed store, hash-verified

29
30// TestGoVersion tests that the Go version specified in go.mod matches ./tool/go version.
31func TestGoVersion(t *testing.T) {
32 // We could special-case ./tool/go path for Windows, but really there is no
33 // need to run it there.
34 if runtime.GOOS == "windows" {
35 t.Skip("Skipping test on Windows")
36 }
37 goModVersion := mustGetGoModVersion(t, true)
38
39 goToolCmd := exec.Command("./tool/go", "version")
40 goToolOutput, err := goToolCmd.Output()
41 if err != nil {
42 t.Fatalf("Failed to get ./tool/go version: %v", err)
43 }
44
45 // Version info will approximately look like 'go version go1.24.4 linux/amd64'.
46 parts := strings.Fields(string(goToolOutput))
47 if len(parts) < 4 {
48 t.Fatalf("Unexpected ./tool/go version output format: %s", goToolOutput)
49 }
50
51 goToolVersion := strings.TrimPrefix(parts[2], "go")
52
53 if goModVersion != goToolVersion {
54 t.Errorf("Go version in go.mod (%q) does not match the version of ./tool/go (%q).\nEnsure that the go.mod refers to the same Go version as ./go.toolchain.rev.",
55 goModVersion, goToolVersion)
56 }
57}
58
59func mustGetGoModVersion(t *testing.T, includePatchVersion bool) string {
60 t.Helper()

Callers

nothing calls this directly

Calls 5

mustGetGoModVersionFunction · 0.85
SkipMethod · 0.65
FatalfMethod · 0.65
ErrorfMethod · 0.65
OutputMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…