Skip to content

Commit 146972c

Browse files
Godriver 3445 (#2004)
1 parent 897e9a5 commit 146972c

File tree

1,966 files changed

+402969
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,966 files changed

+402969
-275
lines changed

.evergreen/config.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ functions:
3232
type: system
3333
params:
3434
directory: src/go.mongodb.org/mongo-driver
35+
- command: shell.exec
36+
params:
37+
working_dir: "src/go.mongodb.org/mongo-driver"
38+
script: |
39+
git submodule update --init
3540
# Make an env.sh and evergreen expansion file with dynamic values
3641
- command: subprocess.exec
3742
params:
@@ -44,10 +49,6 @@ functions:
4449
# Define an alias for the task runner script.
4550
TASK_RUNNER_ALIAS: &task-runner src/go.mongodb.org/mongo-driver/.evergreen/run-task.sh
4651
args: [.evergreen/setup-system.sh]
47-
- command: subprocess.exec
48-
params:
49-
binary: bash
50-
args: [*task-runner, init-submodule]
5152
- command: expansions.update
5253
params:
5354
file: src/go.mongodb.org/mongo-driver/expansion.yml

bson/benchmark_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ var nestedInstance = nestedtest1{
130130
},
131131
}
132132

133-
const extendedBSONDir = "../testdata/extended_bson"
133+
const extendedBSONDir = "../testdata/extended-bson"
134134

135135
var (
136136
extJSONFiles map[string]map[string]interface{}

bson/bson_binary_vector_spec_test.go

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import (
1515
"testing"
1616

1717
"go.mongodb.org/mongo-driver/v2/internal/require"
18+
"go.mongodb.org/mongo-driver/v2/internal/spectest"
1819
)
1920

20-
const bsonBinaryVectorDir = "../testdata/bson-binary-vector/"
21+
var bsonBinaryVectorDir = spectest.Path("bson-binary-vector")
2122

2223
type bsonBinaryVectorTests struct {
2324
Description string `json:"description"`
@@ -128,18 +129,7 @@ func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVector
128129
require.NoError(t, err, "decoding canonical BSON")
129130

130131
t.Run("Unmarshaling", func(t *testing.T) {
131-
skipCases := map[string]string{
132-
"Overflow Vector INT8": "compile-time restriction",
133-
"Underflow Vector INT8": "compile-time restriction",
134-
"INT8 with float inputs": "compile-time restriction",
135-
"Overflow Vector PACKED_BIT": "compile-time restriction",
136-
"Underflow Vector PACKED_BIT": "compile-time restriction",
137-
"Vector with float values PACKED_BIT": "compile-time restriction",
138-
"Negative padding PACKED_BIT": "compile-time restriction",
139-
}
140-
if reason, ok := skipCases[test.Description]; ok {
141-
t.Skipf("skip test case %s: %s", test.Description, reason)
142-
}
132+
spectest.CheckSkip(t)
143133

144134
errMap := map[string]string{
145135
"FLOAT32 with padding": "padding must be 0",
@@ -163,24 +153,7 @@ func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVector
163153
})
164154

165155
t.Run("Marshaling", func(t *testing.T) {
166-
skipCases := map[string]string{
167-
"FLOAT32 with padding": "private padding field",
168-
"Insufficient vector data with 3 bytes FLOAT32": "invalid case",
169-
"Insufficient vector data with 5 bytes FLOAT32": "invalid case",
170-
"Overflow Vector INT8": "compile-time restriction",
171-
"Underflow Vector INT8": "compile-time restriction",
172-
"INT8 with padding": "private padding field",
173-
"INT8 with float inputs": "compile-time restriction",
174-
"Overflow Vector PACKED_BIT": "compile-time restriction",
175-
"Underflow Vector PACKED_BIT": "compile-time restriction",
176-
"Vector with float values PACKED_BIT": "compile-time restriction",
177-
"Padding specified with no vector data PACKED_BIT": "run in alternative case",
178-
"Exceeding maximum padding PACKED_BIT": "run in alternative case",
179-
"Negative padding PACKED_BIT": "compile-time restriction",
180-
}
181-
if reason, ok := skipCases[test.Description]; ok {
182-
t.Skipf("skip test case %s: %s", test.Description, reason)
183-
}
156+
spectest.CheckSkip(t)
184157

185158
t.Parallel()
186159

bson/bson_corpus_spec_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/google/go-cmp/cmp"
2424
"go.mongodb.org/mongo-driver/v2/internal/assert"
2525
"go.mongodb.org/mongo-driver/v2/internal/require"
26+
"go.mongodb.org/mongo-driver/v2/internal/spectest"
2627
)
2728

2829
type testCase struct {
@@ -57,7 +58,7 @@ type parseErrorTestCase struct {
5758
String string `json:"string"`
5859
}
5960

60-
const dataDir = "../testdata/bson-corpus/"
61+
var dataDir = spectest.Path("bson-corpus/tests")
6162

6263
func findJSONFilesInDir(dir string) ([]string, error) {
6364
files := make([]string, 0)

internal/integration/client_side_encryption_spec_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ package integration
1111

1212
import (
1313
"os"
14-
"path"
14+
"path/filepath"
1515
"regexp"
1616
"testing"
17-
)
1817

19-
const (
20-
encryptionSpecName = "client-side-encryption/legacy"
18+
"go.mongodb.org/mongo-driver/v2/internal/spectest"
2119
)
2220

21+
var encryptionSpecDir = spectest.Path("client-side-encryption/tests/legacy")
22+
2323
func verifyClientSideEncryptionVarsSet(t *testing.T) {
2424
t.Helper()
2525

@@ -53,7 +53,7 @@ func verifyClientSideEncryptionVarsSet(t *testing.T) {
5353
func TestClientSideEncryptionSpec(t *testing.T) {
5454
verifyClientSideEncryptionVarsSet(t)
5555

56-
for _, fileName := range jsonFilesInDir(t, path.Join(dataPath, encryptionSpecName)) {
56+
for _, fileName := range jsonFilesInDir(t, encryptionSpecDir) {
5757
t.Run(fileName, func(t *testing.T) {
5858
re := regexp.MustCompile(`fle2\-Range\-.*\-Correctness`)
5959
if re.Match([]byte(fileName)) {
@@ -62,7 +62,7 @@ func TestClientSideEncryptionSpec(t *testing.T) {
6262
if fileName == "kmipKMS.json" && "" == os.Getenv("KMS_MOCK_SERVERS_RUNNING") {
6363
t.Skipf("Skipping test as KMS_MOCK_SERVERS_RUNNING is not set")
6464
}
65-
runSpecTestFile(t, encryptionSpecName, fileName)
65+
runSpecTestFile(t, filepath.Join(encryptionSpecDir, fileName))
6666
})
6767
}
6868
}

internal/integration/cmd_monitoring_helpers_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,30 @@ func compareValues(mt *mtest.T, key string, expected, actual bson.RawValue) erro
8383
if typeVal, err := e.LookupErr("$$type"); err == nil {
8484
// $$type represents a type assertion
8585
// for example {field: {$$type: "binData"}} should assert that "field" is an element with a binary value
86-
return checkValueType(mt, key, actual.Type, typeVal.StringValue())
86+
types := []string{}
87+
switch typeVal.Type {
88+
case bson.TypeArray:
89+
elems, err := typeVal.Array().Values()
90+
if err != nil {
91+
return fmt.Errorf("error getting expected types: %v", err)
92+
}
93+
94+
for _, elem := range elems {
95+
types = append(types, elem.StringValue())
96+
}
97+
case bson.TypeString:
98+
types = append(types, typeVal.StringValue())
99+
}
100+
101+
// If at least one of the types does not return an error, then the test
102+
// has passed.
103+
for _, t := range types {
104+
if err := checkValueType(mt, key, actual.Type, t); err == nil {
105+
return nil
106+
}
107+
}
108+
109+
return fmt.Errorf("BSON type mismatch for key %s; expected one of %v, got %s", key, types, actual.Type)
87110
}
88111

89112
a := actual.Document()

internal/integration/initial_dns_seedlist_discovery_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"go.mongodb.org/mongo-driver/v2/internal/assert"
2222
"go.mongodb.org/mongo-driver/v2/internal/integration/mtest"
2323
"go.mongodb.org/mongo-driver/v2/internal/serverselector"
24+
"go.mongodb.org/mongo-driver/v2/internal/spectest"
2425
"go.mongodb.org/mongo-driver/v2/mongo"
2526
"go.mongodb.org/mongo-driver/v2/mongo/options"
2627
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
@@ -29,9 +30,7 @@ import (
2930
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology"
3031
)
3132

32-
const (
33-
seedlistDiscoveryTestsBaseDir = "../../testdata/initial-dns-seedlist-discovery"
34-
)
33+
var seedlistDiscoveryTestsBaseDir = spectest.Path("initial-dns-seedlist-discovery/tests")
3534

3635
type seedlistTest struct {
3736
URI string `bson:"uri"`

internal/integration/unified/unified_spec_runner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func runTestDirectory(t *testing.T, directoryPath string, expectValidFail bool)
9090

9191
// runTestFile runs the tests in the given file, with expectValidFail determining whether the tests should expect to pass or fail
9292
func runTestFile(t *testing.T, filepath string, expectValidFail bool, opts ...*Options) {
93+
//spectest.CheckSkip(t)
9394
content, err := ioutil.ReadFile(filepath)
9495
assert.Nil(t, err, "ReadFile error for file %q: %v", filepath, err)
9596

internal/integration/unified/unified_spec_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ package unified
88

99
import (
1010
"context"
11+
"path"
1112
"testing"
1213

1314
"go.mongodb.org/mongo-driver/v2/internal/spectest"
1415
)
1516

1617
var (
18+
nonGitSubmodulePassDirectories = []string{
19+
"unified-test-format/valid-pass",
20+
}
1721
passDirectories = []string{
18-
"unified-test-format/tests/valid-pass",
1922
"versioned-api/tests",
2023
"crud/tests/unified",
2124
"change-streams/tests/unified",
@@ -29,20 +32,21 @@ var (
2932
"retryable-reads/tests/unified",
3033
"retryable-writes/tests/unified",
3134
"client-side-encryption/tests/unified",
32-
"client-side-operations-timeout/tests",
35+
//"client-side-operations-timeout/tests",
3336
"gridfs/tests",
3437
"server-selection/tests/logging",
3538
"server-discovery-and-monitoring/tests/unified",
3639
"run-command/tests/unified",
3740
"index-management/tests",
38-
"transactions-convenient-api/tests/unified",
3941
"atlas-data-lake-testing/tests/unified",
4042
}
4143
failDirectories = []string{
4244
"unified-test-format/tests/valid-fail",
4345
}
4446
)
4547

48+
const dataDirectory = "../../../testdata"
49+
4650
func TestUnifiedSpec(t *testing.T) {
4751
// Ensure the cluster is in a clean state before test execution begins.
4852
if err := terminateOpenSessions(context.Background()); err != nil {
@@ -55,6 +59,12 @@ func TestUnifiedSpec(t *testing.T) {
5559
})
5660
}
5761

62+
for _, testDir := range nonGitSubmodulePassDirectories {
63+
t.Run(testDir, func(t *testing.T) {
64+
runTestDirectory(t, path.Join(dataDirectory, testDir), false)
65+
})
66+
}
67+
5868
for _, testDir := range failDirectories {
5969
t.Run(testDir, func(t *testing.T) {
6070
runTestDirectory(t, spectest.Path(testDir), true)

internal/integration/unified_spec_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"fmt"
1414
"io/ioutil"
1515
"os"
16+
"path"
1617
"path/filepath"
1718
"reflect"
1819
"sync"
@@ -161,6 +162,12 @@ var directories = []string{
161162
"read-write-concern/tests/operation",
162163
}
163164

165+
var nonGitSubmodulePassDirectories = []string{
166+
"convenient-transactions",
167+
}
168+
169+
const dataPath string = "../../testdata/"
170+
164171
var checkOutcomeOpts = options.Collection().SetReadPreference(readpref.Primary()).SetReadConcern(readconcern.Local())
165172
var specTestRegistry = func() *bson.Registry {
166173
reg := bson.NewRegistry()
@@ -179,11 +186,25 @@ func TestUnifiedSpecs(t *testing.T) {
179186
}
180187
})
181188
}
189+
190+
for _, specDir := range nonGitSubmodulePassDirectories {
191+
t.Run(specDir, func(t *testing.T) {
192+
for _, fileName := range jsonFilesInDir(t, path.Join(dataPath, specDir)) {
193+
fmt.Println(fileName)
194+
t.Run(fileName, func(t *testing.T) {
195+
runSpecTestFile(t, filepath.Join(dataPath, specDir, fileName))
196+
})
197+
}
198+
})
199+
}
182200
}
183201

184202
// specDir: name of directory for a spec in the data/ folder
185203
// fileName: name of test file in specDir
186204
func runSpecTestFile(t *testing.T, filePath string) {
205+
// It's possible that a JSON blob does not conform to our spec test format.
206+
spectest.CheckSkip(t)
207+
187208
content, err := ioutil.ReadFile(filePath)
188209
assert.Nil(t, err, "unable to read spec test file %v: %v", filePath, err)
189210

0 commit comments

Comments
 (0)