Skip to content

Commit 92416b2

Browse files
committed
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 <[email protected]> Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent ccacb6f commit 92416b2

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

internal/licenses/licenses_test.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"os"
1616
"path"
1717
"path/filepath"
18-
"runtime"
1918
"sort"
2019
"strings"
2120
"testing"
@@ -229,18 +228,6 @@ var mitCoverage = lc.Coverage{
229228
Match: []lc.Match{{ID: "MIT"}},
230229
}
231230

232-
// testDataPath returns a path corresponding to a path relative to the calling
233-
// test file. For convenience, rel is assumed to be "/"-delimited.
234-
//
235-
// It panics on failure.
236-
func testDataPath(rel string) string {
237-
_, filename, _, ok := runtime.Caller(1)
238-
if !ok {
239-
panic("unable to determine relative path")
240-
}
241-
return filepath.Clean(filepath.Join(filepath.Dir(filename), filepath.FromSlash(rel)))
242-
}
243-
244231
func TestModuleIsRedistributable(t *testing.T) {
245232
// More thorough tests of the helper functions are below. This end-to-end test covers
246233
// a few key cases using actual zip files.
@@ -288,7 +275,7 @@ func TestModuleIsRedistributable(t *testing.T) {
288275
},
289276
} {
290277
t.Run(test.filename, func(t *testing.T) {
291-
f, err := os.Open(filepath.Join(testDataPath("testdata"), test.filename+".zip"))
278+
f, err := os.Open(filepath.Join("testdata", test.filename+".zip"))
292279
if err != nil {
293280
t.Fatal(err)
294281
}

0 commit comments

Comments
 (0)