From 92416b2556a4da821deb05a70c3ff92657654c17 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Thu, 31 Aug 2023 14:20:19 -0400 Subject: [PATCH] internal/licences: use relative path to open testdata We don't need to do the extra work to construct the that's being done in testDataPath because the test will be run in the directory of the test file. In addition, this is broken on the android builders because they build on a different machine than where the tests run. For golang/go#61209 Change-Id: I066cde3d972e21d52240d9c518524569d60a65f7 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/524798 kokoro-CI: kokoro Run-TryBot: Michael Matloob TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills LUCI-TryBot-Result: Go LUCI --- internal/licenses/licenses_test.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/internal/licenses/licenses_test.go b/internal/licenses/licenses_test.go index 0899e407f..9d8e66277 100644 --- a/internal/licenses/licenses_test.go +++ b/internal/licenses/licenses_test.go @@ -15,7 +15,6 @@ import ( "os" "path" "path/filepath" - "runtime" "sort" "strings" "testing" @@ -229,18 +228,6 @@ var mitCoverage = lc.Coverage{ Match: []lc.Match{{ID: "MIT"}}, } -// testDataPath returns a path corresponding to a path relative to the calling -// test file. For convenience, rel is assumed to be "/"-delimited. -// -// It panics on failure. -func testDataPath(rel string) string { - _, filename, _, ok := runtime.Caller(1) - if !ok { - panic("unable to determine relative path") - } - return filepath.Clean(filepath.Join(filepath.Dir(filename), filepath.FromSlash(rel))) -} - func TestModuleIsRedistributable(t *testing.T) { // More thorough tests of the helper functions are below. This end-to-end test covers // a few key cases using actual zip files. @@ -288,7 +275,7 @@ func TestModuleIsRedistributable(t *testing.T) { }, } { t.Run(test.filename, func(t *testing.T) { - f, err := os.Open(filepath.Join(testDataPath("testdata"), test.filename+".zip")) + f, err := os.Open(filepath.Join("testdata", test.filename+".zip")) if err != nil { t.Fatal(err) }