Skip to content

Commit fff4880

Browse files
authored
Merge pull request #2001 from matthewdale/godriver3445-improve-testpath
GODRIVER-3445 Refactor how spec test paths are built and update test dirs.
2 parents 2483392 + 132d39d commit fff4880

File tree

15 files changed

+66
-157
lines changed

15 files changed

+66
-157
lines changed

.evergreen/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ functions:
4444
# Define an alias for the task runner script.
4545
TASK_RUNNER_ALIAS: &task-runner src/go.mongodb.org/mongo-driver/.evergreen/run-task.sh
4646
args: [.evergreen/setup-system.sh]
47+
- command: subprocess.exec
48+
params:
49+
binary: bash
50+
args: [*task-runner, init-submodule]
4751
- command: expansions.update
4852
params:
4953
file: src/go.mongodb.org/mongo-driver/expansion.yml

Taskfile.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ tasks:
1717

1818
check-license: bash etc/check_license.sh
1919

20+
init-submodule: git submodule update --init
21+
2022
build:
2123
deps: [install-libmongocrypt]
2224
cmds:
@@ -149,9 +151,9 @@ tasks:
149151
evg-test-load-balancers:
150152
# Load balancer should be tested with all unified tests as well as tests in the following
151153
# components: retryable reads, retryable writes, change streams, initial DNS seedlist discovery.
152-
- go test ${BUILD_TAGS} ./internal/integration -run TestUnifiedSpecs/retryable-reads -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
153-
- go test ${BUILD_TAGS} ./internal/integration -run TestRetryableWritesSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
154-
- go test ${BUILD_TAGS} ./internal/integration -run TestChangeStreamSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
154+
- go test ${BUILD_TAGS} ./internal/integration/unified -run TestUnifiedSpec/retryable-reads -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
155+
- go test ${BUILD_TAGS} ./internal/integration/unified -run TestUnifiedSpec/retryable-writes -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
156+
- go test ${BUILD_TAGS} ./internal/integration/unified -run TestUnifiedSpec/change-streams -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
155157
- go test ${BUILD_TAGS} ./internal/integration -run TestInitialDNSSeedlistDiscoverySpec/load_balanced -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
156158
- go test ${BUILD_TAGS} ./internal/integration -run TestLoadBalancerSupport -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
157159
- go test ${BUILD_TAGS} ./internal/integration -run TestLoadBalancedConnectionHandshake -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
@@ -174,13 +176,10 @@ tasks:
174176
- go test ${BUILD_TAGS} ./internal/integration -run TestWriteConcernError -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
175177
- go test ${BUILD_TAGS} ./internal/integration -run TestErrorsCodeNamePropagated -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
176178
- go test ${BUILD_TAGS} ./internal/integration -run TestLoadBalancerSupport -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
177-
- go test ${BUILD_TAGS} ./internal/integration -run TestUnifiedSpecs/retryable-reads -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
178179
- go test ${BUILD_TAGS} ./internal/integration -run TestRetryableReadsProse -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
179180
- go test ${BUILD_TAGS} ./internal/integration -run TestRetryableWritesSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
180181
- go test ${BUILD_TAGS} ./internal/integration -run TestRetryableWritesProse -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
181-
- go test ${BUILD_TAGS} ./internal/integration -run TestUnifiedSpecs/sessions -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
182182
- go test ${BUILD_TAGS} ./internal/integration -run TestSessionsProse -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
183-
- go test ${BUILD_TAGS} ./internal/integration -run TestUnifiedSpecs/transactions/legacy -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
184183
- go test ${BUILD_TAGS} ./internal/integration -run TestConvenientTransactions -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
185184
- go test ${BUILD_TAGS} ./internal/integration -run TestCursor -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
186185
- go test ${BUILD_TAGS} ./internal/integration/unified -run TestUnifiedSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite

internal/integration/retryable_writes_spec_test.go

Lines changed: 0 additions & 86 deletions
This file was deleted.

internal/integration/unified/unified_spec_runner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ func runTestFile(t *testing.T, filepath string, expectValidFail bool, opts ...*O
9898
mtOpts := mtest.NewOptions().
9999
RunOn(fileReqs...).
100100
CreateClient(false)
101+
if strings.Contains(filepath, "atlas-data-lake-testing") {
102+
mtOpts.AtlasDataLake(true)
103+
}
101104
mt := mtest.New(t, mtOpts)
102105

103106
for _, testCase := range testCases {

internal/integration/unified/unified_spec_test.go

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,41 @@ package unified
88

99
import (
1010
"context"
11-
"path"
1211
"testing"
12+
13+
"go.mongodb.org/mongo-driver/v2/internal/spectest"
1314
)
1415

1516
var (
1617
passDirectories = []string{
17-
"unified-test-format/valid-pass",
18-
"versioned-api",
19-
"crud/unified",
20-
"change-streams",
21-
"transactions/unified",
22-
"load-balancers",
23-
"collection-management",
24-
"command-monitoring",
25-
"command-monitoring/logging",
26-
"connection-monitoring-and-pooling/logging",
27-
"sessions",
28-
"retryable-reads/unified",
29-
"retryable-writes/unified",
30-
"client-side-encryption/unified",
31-
"client-side-operations-timeout",
32-
"gridfs",
33-
"server-selection/logging",
34-
"server-discovery-and-monitoring/unified",
35-
"run-command",
36-
"index-management",
18+
"unified-test-format/tests/valid-pass",
19+
"versioned-api/tests",
20+
"crud/tests/unified",
21+
"change-streams/tests/unified",
22+
"transactions/tests/unified",
23+
"load-balancers/tests",
24+
"collection-management/tests",
25+
"command-logging-and-monitoring/tests/monitoring",
26+
"command-logging-and-monitoring/tests/logging",
27+
"connection-monitoring-and-pooling/tests/logging",
28+
"sessions/tests",
29+
"retryable-reads/tests/unified",
30+
"retryable-writes/tests/unified",
31+
"client-side-encryption/tests/unified",
32+
"client-side-operations-timeout/tests",
33+
"gridfs/tests",
34+
"server-selection/tests/logging",
35+
"server-discovery-and-monitoring/tests/unified",
36+
"run-command/tests/unified",
37+
"index-management/tests",
38+
"transactions-convenient-api/tests/unified",
39+
"atlas-data-lake-testing/tests/unified",
3740
}
3841
failDirectories = []string{
39-
"unified-test-format/valid-fail",
42+
"unified-test-format/tests/valid-fail",
4043
}
4144
)
4245

43-
const (
44-
dataDirectory = "../../../testdata"
45-
)
46-
4746
func TestUnifiedSpec(t *testing.T) {
4847
// Ensure the cluster is in a clean state before test execution begins.
4948
if err := terminateOpenSessions(context.Background()); err != nil {
@@ -52,13 +51,13 @@ func TestUnifiedSpec(t *testing.T) {
5251

5352
for _, testDir := range passDirectories {
5453
t.Run(testDir, func(t *testing.T) {
55-
runTestDirectory(t, path.Join(dataDirectory, testDir), false)
54+
runTestDirectory(t, spectest.Path(testDir), false)
5655
})
5756
}
5857

5958
for _, testDir := range failDirectories {
6059
t.Run(testDir, func(t *testing.T) {
61-
runTestDirectory(t, path.Join(dataDirectory, testDir), true)
60+
runTestDirectory(t, spectest.Path(testDir), true)
6261
})
6362
}
6463
}

internal/integration/unified_spec_test.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"fmt"
1414
"io/ioutil"
1515
"os"
16-
"path"
16+
"path/filepath"
1717
"reflect"
1818
"sync"
1919
"testing"
@@ -157,14 +157,8 @@ type operationError struct {
157157
ErrorLabelsOmit []string `bson:"errorLabelsOmit"`
158158
}
159159

160-
const dataPath string = "../../testdata/"
161-
162160
var directories = []string{
163-
"transactions/legacy",
164-
"convenient-transactions",
165-
"retryable-reads/legacy",
166-
"read-write-concern/operation",
167-
"atlas-data-lake-testing",
161+
"read-write-concern/tests/operation",
168162
}
169163

170164
var checkOutcomeOpts = options.Collection().SetReadPreference(readpref.Primary()).SetReadConcern(readconcern.Local())
@@ -178,9 +172,9 @@ var specTestRegistry = func() *bson.Registry {
178172
func TestUnifiedSpecs(t *testing.T) {
179173
for _, specDir := range directories {
180174
t.Run(specDir, func(t *testing.T) {
181-
for _, fileName := range jsonFilesInDir(t, path.Join(dataPath, specDir)) {
175+
for _, fileName := range jsonFilesInDir(t, spectest.Path(specDir)) {
182176
t.Run(fileName, func(t *testing.T) {
183-
runSpecTestFile(t, specDir, fileName)
177+
runSpecTestFile(t, filepath.Join(specDir, fileName))
184178
})
185179
}
186180
})
@@ -189,8 +183,7 @@ func TestUnifiedSpecs(t *testing.T) {
189183

190184
// specDir: name of directory for a spec in the data/ folder
191185
// fileName: name of test file in specDir
192-
func runSpecTestFile(t *testing.T, specDir, fileName string) {
193-
filePath := path.Join(dataPath, specDir, fileName)
186+
func runSpecTestFile(t *testing.T, filePath string) {
194187
content, err := ioutil.ReadFile(filePath)
195188
assert.Nil(t, err, "unable to read spec test file %v: %v", filePath, err)
196189

@@ -206,9 +199,6 @@ func runSpecTestFile(t *testing.T, specDir, fileName string) {
206199
mtOpts := mtest.NewOptions().
207200
RunOn(testFile.RunOn...).
208201
CreateClient(false)
209-
if specDir == "atlas-data-lake-testing" {
210-
mtOpts.AtlasDataLake(true)
211-
}
212202
mt := mtest.New(t, mtOpts)
213203

214204
for _, test := range testFile.Tests {

internal/serverselector/server_selector_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func compareServers(t *testing.T, expected []*serverDesc, actual []description.S
157157
}
158158
}
159159

160-
var maxStalenessTestsDir = spectest.TestPath(2, "max-staleness")
160+
var maxStalenessTestsDir = spectest.Path("max-staleness/tests")
161161

162162
// Test case for all max staleness spec tests.
163163
func TestMaxStalenessSpec(t *testing.T) {
@@ -176,7 +176,7 @@ func TestMaxStalenessSpec(t *testing.T) {
176176
}
177177
}
178178

179-
var selectorTestsDir = spectest.TestPath(2, "server-selection")
179+
var selectorTestsDir = spectest.Path("server-selection/tests")
180180

181181
func selectServers(t *testing.T, test *testCase) error {
182182
servers := make([]description.Server, 0, len(test.TopologyDescription.Servers))

internal/spectest/spectest.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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,20 @@ 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 given specifications repo file or
43+
// subdirectory.
44+
func Path(subdir string) string {
45+
testPath, err := filepath.Abs("../../../testdata/specifications/source/")
46+
if err != nil {
47+
panic(err)
48+
}
4949

50-
return fullPath
50+
return filepath.Join(testPath, subdir)
5151
}

mongo/read_write_concern_spec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var (
3636
reg.RegisterTypeMapEntry(bson.TypeEmbeddedDocument, reflect.TypeOf(bson.Raw{}))
3737
return reg
3838
}()
39-
readWriteConcernTestsDir = spectest.TestPath(1, "read-write-concern")
39+
readWriteConcernTestsDir = spectest.Path("read-write-concern/tests")
4040
)
4141

4242
type connectionStringTestFile struct {

x/mongo/driver/auth/auth_spec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type testContainer struct {
3838
}
3939

4040
// Note a test supporting the deprecated gssapiServiceName property was removed from data/auth/auth_tests.json
41-
var authTestsDir = spectest.TestPath(4, "auth", "legacy")
41+
var authTestsDir = spectest.Path("auth/tests/legacy")
4242

4343
func runTestsInFile(t *testing.T, dirname string, filename string) {
4444
filepath := path.Join(dirname, filename)

0 commit comments

Comments
 (0)