apidiff: pull test go version into a const The version of Go used to load the code under test was buried in a string, so it was hard to find. Make it a const at the top of the file. Change-Id: I7ad221759d7c84ccf3ded5ca1403898e5f343fad Reviewed-on: https://go-review.googlesource.com/c/exp/+/639737 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
diff --git a/apidiff/apidiff_test.go b/apidiff/apidiff_test.go index a20fa9b..6d338d7 100644 --- a/apidiff/apidiff_test.go +++ b/apidiff/apidiff_test.go
@@ -17,6 +17,9 @@ "golang.org/x/tools/go/packages/packagestest" ) +// The version to write into the go.mod file used to load the packages being tested. +const testGoVersion = "1.22" + func TestModuleChanges(t *testing.T) { packagestest.TestAll(t, testModuleChanges) } @@ -129,7 +132,8 @@ if err := os.MkdirAll(filepath.Join(dir, "src", "apidiff"), 0700); err != nil { t.Fatal(err) } - if err := os.WriteFile(filepath.Join(dir, "src", "apidiff", "go.mod"), []byte("module apidiff\ngo 1.22\n"), 0600); err != nil { + goMod := fmt.Sprintf("module apidiff\ngo %s\n", testGoVersion) + if err := os.WriteFile(filepath.Join(dir, "src", "apidiff", "go.mod"), []byte(goMod), 0600); err != nil { t.Fatal(err) }