Skip to content

Commit

Permalink
internal/licences: use relative path to open testdata
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
matloob committed Aug 31, 2023
1 parent ccacb6f commit 92416b2
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions internal/licenses/licenses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 92416b2

Please sign in to comment.