Skip to content

Commit 0b6ac65

Browse files
committed
GODRIVER-3445 Make spectest.Path work for any caller.
1 parent fff4880 commit 0b6ac65

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

internal/spectest/spectest.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"path"
1212
"path/filepath"
13+
"runtime"
1314
"testing"
1415

1516
"go.mongodb.org/mongo-driver/v2/internal/require"
@@ -42,10 +43,13 @@ func FindJSONFilesInDir(t *testing.T, dir string) []string {
4243
// Path returns the absolute path to the given specifications repo file or
4344
// subdirectory.
4445
func Path(subdir string) string {
45-
testPath, err := filepath.Abs("../../../testdata/specifications/source/")
46-
if err != nil {
47-
panic(err)
46+
_, file, _, ok := runtime.Caller(0)
47+
if !ok {
48+
panic("unable to get current file path from call stack")
4849
}
4950

50-
return filepath.Join(testPath, subdir)
51+
// Get the repository root path from the current Go file path.
52+
root := filepath.Dir(filepath.Dir(filepath.Dir(file)))
53+
54+
return filepath.Join(root, "testdata", "specifications", "source", subdir)
5155
}

0 commit comments

Comments
 (0)