Skip to content

Commit 9d03793

Browse files
GODRIVER-3444 Resolve merge conflicts
2 parents a435efe + 8c13bc5 commit 9d03793

File tree

325 files changed

+4740
-1895
lines changed

Some content is hidden

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

325 files changed

+4740
-1895
lines changed

.evergreen/config.yml

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

.github/workflows/merge-up.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Merge up
2+
3+
on:
4+
push:
5+
branches:
6+
- release/*.*
7+
- v*
8+
9+
permissions:
10+
id-token: write
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
merge-up:
16+
name: Create merge up pull request
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
21+
with:
22+
app_id: ${{ vars.PR_APP_ID }}
23+
private_key: ${{ secrets.PR_APP_PRIVATE_KEY }}
24+
# Make sure to include fetch-depth 0 so all branches are fetched, not
25+
# just the current one
26+
fetch-depth: 0
27+
28+
- name: Create pull request
29+
id: create-pull-request
30+
uses: alcaeus/automatic-merge-up-action@main
31+
with:
32+
ref: ${{ github.ref_name }}
33+
branchNamePattern: 'release/<major>.<minor>'
34+
devBranchNamePattern: 'v<major>'
35+
fallbackBranch: 'master'
36+
enableAutoMerge: true

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ tasks:
3030

3131
build-compile-check: bash etc/compile_check.sh
3232

33+
build-compile-check-all: bash etc/run-compile-check-test.sh
34+
3335
build-aws-ecs-test: go build ${BUILD_TAGS} ./internal/cmd/testaws/main.go
3436

3537
cross-compile:
@@ -199,7 +201,7 @@ tasks:
199201

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

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

204206
build-kms-test: go build ${BUILD_TAGS} ./internal/cmd/testkms
205207

bson/bson_corpus_spec_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,7 @@ func runTest(t *testing.T, file string) {
275275
content, err := os.ReadFile(filepath)
276276
require.NoError(t, err)
277277

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) {
278+
t.Run(file, func(t *testing.T) {
283279
var test testCase
284280
require.NoError(t, json.Unmarshal(content, &test))
285281

@@ -429,7 +425,7 @@ func runTest(t *testing.T, file string) {
429425
})
430426
}
431427

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

bson/bson_test.go

Lines changed: 17 additions & 6 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
})
@@ -584,11 +586,20 @@ func TestMapCodec(t *testing.T) {
584586
}
585587

586588
func TestExtJSONEscapeKey(t *testing.T) {
587-
doc := D{{Key: "\\usb#", Value: int32(1)}}
589+
doc := D{
590+
{
591+
Key: "\\usb#",
592+
Value: int32(1),
593+
},
594+
{
595+
Key: "regex",
596+
Value: Regex{Pattern: "ab\\\\\\\"ab", Options: "\""},
597+
},
598+
}
588599
b, err := MarshalExtJSON(&doc, false, false)
589600
noerr(t, err)
590601

591-
want := "{\"\\\\usb#\":1}"
602+
want := `{"\\usb#":1,"regex":{"$regularExpression":{"pattern":"ab\\\\\\\"ab","options":"\""}}}`
592603
if diff := cmp.Diff(want, string(b)); diff != "" {
593604
t.Errorf("Marshaled documents do not match. got %v, want %v", string(b), want)
594605
}

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+
}

bson/encoder.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,21 @@ func (e *Encoder) NilByteSliceAsEmpty() {
108108
// TODO struct fields once the logic is updated to also inspect private struct fields.
109109

110110
// OmitZeroStruct causes the Encoder to consider the zero value for a struct (e.g. MyStruct{})
111-
// as empty and omit it from the marshaled BSON when the "omitempty" struct tag option is set.
111+
// as empty and omit it from the marshaled BSON when the "omitempty" struct tag option is set
112+
// or the OmitEmpty() method is called.
112113
//
113114
// Note that the Encoder only examines exported struct fields when determining if a struct is the
114115
// zero value. It considers pointers to a zero struct value (e.g. &MyStruct{}) not empty.
115116
func (e *Encoder) OmitZeroStruct() {
116117
e.ec.omitZeroStruct = true
117118
}
118119

120+
// OmitEmpty causes the Encoder to omit empty values from the marshaled BSON as the "omitempty"
121+
// struct tag option is set.
122+
func (e *Encoder) OmitEmpty() {
123+
e.ec.omitEmpty = true
124+
}
125+
119126
// UseJSONStructTags causes the Encoder to fall back to using the "json" struct tag if a "bson"
120127
// struct tag is not specified.
121128
func (e *Encoder) UseJSONStructTags() {

bson/encoder_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"errors"
1212
"reflect"
1313
"testing"
14+
"time"
1415

1516
"go.mongodb.org/mongo-driver/v2/internal/assert"
1617
"go.mongodb.org/mongo-driver/v2/internal/require"
@@ -248,6 +249,42 @@ func TestEncoderConfiguration(t *testing.T) {
248249
}{},
249250
want: bsoncore.NewDocumentBuilder().Build(),
250251
},
252+
// Test that OmitZeroStruct omits empty structs from the marshaled document if
253+
// OmitEmpty is also set.
254+
{
255+
description: "OmitEmpty with non-zeroer struct",
256+
configure: func(enc *Encoder) {
257+
enc.OmitZeroStruct()
258+
enc.OmitEmpty()
259+
},
260+
input: struct {
261+
Zero zeroStruct
262+
}{},
263+
want: bsoncore.NewDocumentBuilder().Build(),
264+
},
265+
// Test that OmitEmpty omits empty values from the marshaled document.
266+
{
267+
description: "OmitEmpty",
268+
configure: func(enc *Encoder) {
269+
enc.OmitEmpty()
270+
},
271+
input: struct {
272+
Zero zeroTest
273+
I64 int64
274+
F64 float64
275+
String string
276+
Boolean bool
277+
Slice []int
278+
Array [0]int
279+
Map map[string]int
280+
Bytes []byte
281+
Time time.Time
282+
Pointer *int
283+
}{
284+
Zero: zeroTest{true},
285+
},
286+
want: bsoncore.NewDocumentBuilder().Build(),
287+
},
251288
// Test that UseJSONStructTags causes the Encoder to fall back to "json" struct tags if
252289
// "bson" struct tags are not available.
253290
{

0 commit comments

Comments
 (0)