Skip to content

Commit 9406f3f

Browse files
Merge branch 'release/2.2' into merge-release/2.1-into-release/2.2-1746485012973
2 parents 67dc47c + e1d31ae commit 9406f3f

File tree

347 files changed

+5882
-2463
lines changed

Some content is hidden

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

347 files changed

+5882
-2463
lines changed

.evergreen/config.yml

Lines changed: 119 additions & 60 deletions
Large diffs are not rendered by default.

.github/dependabot.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ updates:
1111
- package-ecosystem: gomod
1212
directory: /
1313
schedule:
14-
interval: "weekly"
14+
interval: "weekly"
15+
- package-ecosystem: "gitsubmodule"
16+
directory: "/"
17+
schedule:
18+
interval: "weekly"

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "specifications"]
2-
path = specifications
3-
url = git@github.com:mongodb/specifications.git
2+
path = testdata/specifications
3+
url = https://github.com/mongodb/specifications

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ See the following resources to learn more about upgrading from version 1.x to 2.
1818
## Requirements
1919

2020
- Go 1.18 or higher. We aim to support the latest versions of Go.
21-
- Go 1.22 or higher is required to run the driver test suite.
22-
- MongoDB 3.6 and higher.
21+
- Go 1.23 or higher is required to run the driver test suite.
22+
- MongoDB 4.0 and higher.
2323

2424
## Installation
2525

Taskfile.yml

Lines changed: 6 additions & 10 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:
@@ -30,6 +32,8 @@ tasks:
3032

3133
build-compile-check: bash etc/compile_check.sh
3234

35+
build-compile-check-all: bash etc/run-compile-check-test.sh
36+
3337
build-aws-ecs-test: go build ${BUILD_TAGS} ./internal/cmd/testaws/main.go
3438

3539
cross-compile:
@@ -123,7 +127,7 @@ tasks:
123127
- go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} DYLD_LIBRARY_PATH=$MACOS_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s -p 1 ./... >> test.suite
124128

125129
evg-test-atlas-data-lake:
126-
- ATLAS_DATA_LAKE_INTEGRATION_TEST=true go test -v ./internal/integration -run TestUnifiedSpecs/atlas-data-lake-testing >> spec_test.suite
130+
- ATLAS_DATA_LAKE_INTEGRATION_TEST=true go test -v ./internal/integration/unified -run TestUnifiedSpec/atlas-data-lake-testing >> spec_test.suite
127131
- ATLAS_DATA_LAKE_INTEGRATION_TEST=true go test -v ./internal/integration -run TestAtlasDataLake >> spec_test.suite
128132

129133
evg-test-enterprise-auth:
@@ -149,9 +153,6 @@ tasks:
149153
evg-test-load-balancers:
150154
# Load balancer should be tested with all unified tests as well as tests in the following
151155
# 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
155156
- go test ${BUILD_TAGS} ./internal/integration -run TestInitialDNSSeedlistDiscoverySpec/load_balanced -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
156157
- go test ${BUILD_TAGS} ./internal/integration -run TestLoadBalancerSupport -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
157158
- go test ${BUILD_TAGS} ./internal/integration -run TestLoadBalancedConnectionHandshake -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
@@ -167,20 +168,15 @@ tasks:
167168
evg-test-serverless:
168169
# Serverless should be tested with all unified tests as well as tests in the following components: CRUD, load balancer,
169170
# retryable reads, retryable writes, sessions, transactions and cursor behavior.
170-
- go test ${BUILD_TAGS} ./internal/integration -run TestCrudSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
171171
- go test ${BUILD_TAGS} ./internal/integration -run TestWriteErrorsWithLabels -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
172172
- go test ${BUILD_TAGS} ./internal/integration -run TestWriteErrorsDetails -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
173173
- go test ${BUILD_TAGS} ./internal/integration -run TestHintErrors -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
174174
- go test ${BUILD_TAGS} ./internal/integration -run TestWriteConcernError -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
175175
- go test ${BUILD_TAGS} ./internal/integration -run TestErrorsCodeNamePropagated -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
176176
- 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
178177
- go test ${BUILD_TAGS} ./internal/integration -run TestRetryableReadsProse -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
179-
- go test ${BUILD_TAGS} ./internal/integration -run TestRetryableWritesSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
180178
- 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
182179
- 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
184180
- go test ${BUILD_TAGS} ./internal/integration -run TestConvenientTransactions -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
185181
- go test ${BUILD_TAGS} ./internal/integration -run TestCursor -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
186182
- go test ${BUILD_TAGS} ./internal/integration/unified -run TestUnifiedSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
@@ -199,7 +195,7 @@ tasks:
199195

200196
evg-test-deployed-lambda-aws: bash ${DRIVERS_TOOLS}/.evergreen/aws_lambda/run-deployed-lambda-aws-tests.sh
201197

202-
evg-gather-test-suites: find . -name \*.suite | xargs tar czf test_suite.tgz
198+
evg-gather-test-suites: find . -name \*.suite | xargs --no-run-if-empty tar czf test_suite.tgz
203199

204200
build-kms-test: go build ${BUILD_TAGS} ./internal/cmd/testkms
205201

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: 4 additions & 7 deletions
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)
@@ -275,11 +276,7 @@ func runTest(t *testing.T, file string) {
275276
content, err := os.ReadFile(filepath)
276277
require.NoError(t, err)
277278

278-
// Remove ".json" from filename.
279-
file = file[:len(file)-5]
280-
testName := "bson_corpus--" + file
281-
282-
t.Run(testName, func(t *testing.T) {
279+
t.Run(file, func(t *testing.T) {
283280
var test testCase
284281
require.NoError(t, json.Unmarshal(content, &test))
285282

@@ -429,7 +426,7 @@ func runTest(t *testing.T, file string) {
429426
})
430427
}
431428

432-
func Test_BsonCorpus(t *testing.T) {
429+
func TestBSONCorpus(t *testing.T) {
433430
jsonFiles, err := findJSONFilesInDir(dataDir)
434431
require.NoErrorf(t, err, "error finding JSON files in %s: %v", dataDir, err)
435432

bson/bson_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package bson
99
import (
1010
"bytes"
1111
"encoding/json"
12+
"errors"
1213
"fmt"
1314
"reflect"
1415
"strconv"
@@ -456,13 +457,14 @@ func TestD_UnmarshalJSON(t *testing.T) {
456457
want := json.Unmarshal([]byte(tc.test), &a)
457458
var b D
458459
got := json.Unmarshal([]byte(tc.test), &b)
459-
switch w := want.(type) {
460-
case *json.UnmarshalTypeError:
460+
w := new(json.UnmarshalTypeError)
461+
if errors.As(want, &w) {
461462
w.Type = reflect.TypeOf(b)
462463
require.IsType(t, want, got)
463-
g := got.(*json.UnmarshalTypeError)
464+
g := new(json.UnmarshalTypeError)
465+
assert.True(t, errors.As(got, &g))
464466
assert.Equal(t, w, g)
465-
default:
467+
} else {
466468
assert.Equal(t, want, got)
467469
}
468470
})

bson/bsoncodec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type EncodeContext struct {
8888
nilSliceAsEmpty bool
8989
nilByteSliceAsEmpty bool
9090
omitZeroStruct bool
91+
omitEmpty bool
9192
useJSONStructTags bool
9293
}
9394

bson/decode_value_fuzz_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (C) MongoDB, Inc. 2025-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package bson
8+
9+
import (
10+
"math"
11+
"strings"
12+
"testing"
13+
)
14+
15+
func FuzzDecodeValue(f *testing.F) {
16+
// Seed the fuzz corpus with all BSON values from the MarshalValue test
17+
// cases.
18+
for _, tc := range marshalValueTestCases {
19+
f.Add(byte(tc.bsontype), tc.bytes)
20+
}
21+
22+
// Also seed the fuzz corpus with special values that we want to test.
23+
values := []any{
24+
// int32, including max and min values.
25+
int32(0), int32(math.MaxInt32), int32(math.MinInt32),
26+
// int64, including max and min values.
27+
int64(0), int64(math.MaxInt64), int64(math.MinInt64),
28+
// string, including empty and large string.
29+
"", strings.Repeat("z", 10_000),
30+
// map
31+
map[string]any{"nested": []any{1, "two", map[string]any{"three": 3}}},
32+
// array
33+
[]any{1, 2, 3, "four"},
34+
}
35+
36+
for _, v := range values {
37+
typ, b, err := MarshalValue(v)
38+
if err != nil {
39+
f.Fatal(err)
40+
}
41+
f.Add(byte(typ), b)
42+
}
43+
44+
f.Fuzz(func(t *testing.T, bsonType byte, data []byte) {
45+
var v any
46+
if err := UnmarshalValue(Type(bsonType), data, &v); err != nil {
47+
return
48+
}
49+
50+
// There is no value encoder for Go "nil" (nil values handled
51+
// differently by each type encoder), so skip anything that unmarshals
52+
// to "nil". It's not clear if MarshalValue should support "nil", but
53+
// for now we skip it.
54+
if v == nil {
55+
t.Logf("data unmarshaled to nil: %v", data)
56+
return
57+
}
58+
59+
typ, encoded, err := MarshalValue(v)
60+
if err != nil {
61+
t.Fatalf("failed to marshal: %v", err)
62+
}
63+
64+
var v2 any
65+
if err := UnmarshalValue(typ, encoded, &v2); err != nil {
66+
t.Fatalf("failed to unmarshal: %v", err)
67+
}
68+
})
69+
}

0 commit comments

Comments
 (0)