@@ -10,7 +10,6 @@ import (
1010 "os"
1111 "path"
1212 "path/filepath"
13- "strings"
1413 "testing"
1514
1615 "go.mongodb.org/mongo-driver/v2/internal/require"
@@ -33,19 +32,21 @@ func FindJSONFilesInDir(t *testing.T, dir string) []string {
3332 files = append (files , entry .Name ())
3433 }
3534
35+ if len (files ) == 0 {
36+ t .Fatalf ("no JSON files found in %q" , dir )
37+ }
38+
3639 return files
3740}
3841
39- // TestPath will construct a path to a test file in the specifications git
40- // submodule. The path will be relative to the current package so a depth should
41- // be provided to indicate how many directories to go up.
42- func TestPath (depth int , testDir string , subDirs ... string ) string {
43- const basePath = "testdata/specifications/source/"
44-
45- // Create a string of "../" repeated 'depth' times
46- relativePath := strings .Repeat ("../" , depth )
47- // Construct the full path
48- fullPath := relativePath + basePath + testDir + "/tests/" + filepath .Join (subDirs ... )
42+ // Path returns the absolute path to the "tests" directory for the given
43+ // specification directory. If the spec test files are nested in a subdirectory,
44+ // pass the subdirectories as additional arguments after the spec directory.
45+ func Path (specDir string , subDirs ... string ) string {
46+ testPath , err := filepath .Abs ("../../../testdata/specifications/source/" )
47+ if err != nil {
48+ panic (err )
49+ }
4950
50- return fullPath
51+ return filepath . Join ( testPath , specDir , "tests" , filepath . Join ( subDirs ... ))
5152}
0 commit comments