Skip to content

Commit

Permalink
Merge branch 'master' into GODRIVER-2348
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez authored Jan 26, 2024
2 parents 51d6c1b + 6109bd1 commit 25368d6
Show file tree
Hide file tree
Showing 34 changed files with 218 additions and 507 deletions.
32 changes: 25 additions & 7 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2580,7 +2580,13 @@ buildvariants:

- matrix_name: "tests-42-plus-zlib-zstd-support"
tags: ["pullrequest"]
matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0", "latest"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
display_name: "${version} ${os-ssl-40}"
tasks:
- name: ".test !.enterprise-auth !.snappy"

- matrix_name: "tests-latest-zlib-zstd-support"
matrix_spec: { version: ["latest"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
display_name: "${version} ${os-ssl-40}"
tasks:
- name: ".test !.enterprise-auth !.snappy"
Expand Down Expand Up @@ -2622,27 +2628,39 @@ buildvariants:

- matrix_name: "race-test"
tags: ["pullrequest"]
matrix_spec: { version: ["latest"], os-ssl-40: ["rhel87-64-go-1-20"] }
matrix_spec: { version: ["7.0"], os-ssl-40: ["rhel87-64-go-1-20"] }
display_name: "Race Detector Test"
tasks:
- name: ".race"

- matrix_name: "versioned-api-test"
tags: ["pullrequest"]
matrix_spec: { version: ["5.0", "6.0", "7.0", "latest"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
matrix_spec: { version: ["5.0", "6.0", "7.0"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
display_name: "API Version ${version} ${os-ssl-40}"
tasks:
- name: ".versioned-api"

- matrix_name: "versioned-api-latest-test"
matrix_spec: { version: ["latest"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
display_name: "API Version ${version} ${os-ssl-40}"
tasks:
- name: ".versioned-api"

- matrix_name: "kms-tls-test"
matrix_spec: { version: ["latest"], os-ssl-40: ["rhel87-64-go-1-20"] }
matrix_spec: { version: ["7.0"], os-ssl-40: ["rhel87-64-go-1-20"] }
display_name: "KMS TLS ${os-ssl-40}"
tasks:
- name: ".kms-tls"

- matrix_name: "load-balancer-test"
tags: ["pullrequest"]
matrix_spec: { version: ["5.0", "6.0", "7.0", "latest", "rapid"], os-ssl-40: ["rhel87-64-go-1-20"] }
matrix_spec: { version: ["5.0", "6.0", "7.0"], os-ssl-40: ["rhel87-64-go-1-20"] }
display_name: "Load Balancer Support ${version} ${os-ssl-40}"
tasks:
- name: ".load-balancer"

- matrix_name: "load-balancer-latest-test"
matrix_spec: { version: ["latest"], os-ssl-40: ["rhel87-64-go-1-20"] }
display_name: "Load Balancer Support ${version} ${os-ssl-40}"
tasks:
- name: ".load-balancer"
Expand All @@ -2655,7 +2673,7 @@ buildvariants:
- "serverless_task_group"

- matrix_name: "kms-kmip-test"
matrix_spec: { version: ["latest"], os-ssl-40: ["rhel87-64-go-1-20"] }
matrix_spec: { version: ["7.0"], os-ssl-40: ["rhel87-64-go-1-20"] }
display_name: "KMS KMIP ${os-ssl-40}"
tasks:
- name: ".kms-kmip"
Expand All @@ -2668,7 +2686,7 @@ buildvariants:
batchtime: 1440 # Run at most once per 24 hours.

- matrix_name: "faas-test"
matrix_spec: { version: ["latest"], os-faas-80: ["rhel87-large-go-1-20"] }
matrix_spec: { version: ["7.0"], os-faas-80: ["rhel87-large-go-1-20"] }
display_name: "FaaS ${version} ${os-faas-80}"
tasks:
- test-aws-lambda-task-group
Expand Down
5 changes: 2 additions & 3 deletions bson/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,10 @@ func TestMapCodec(t *testing.T) {
mapRegistry := NewRegistry()
mapRegistry.RegisterKindEncoder(reflect.Map, mapCodec)
buf := new(bytes.Buffer)
vw, err := bsonrw.NewBSONValueWriter(buf)
assert.Nil(t, err)
vw := bsonrw.NewValueWriter(buf)
enc := NewEncoder(vw)
enc.SetRegistry(mapRegistry)
err = enc.Encode(mapObj)
err := enc.Encode(mapObj)
assert.Nil(t, err, "Encode error: %v", err)
str := buf.String()
assert.True(t, strings.Contains(str, tc.key), "expected result to contain %v, got: %v", tc.key, str)
Expand Down
32 changes: 16 additions & 16 deletions bson/bsoncodec/default_value_decoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2427,7 +2427,7 @@ func TestDefaultValueDecoders(t *testing.T) {
buildDocument(bsoncore.AppendNullElement(nil, "bar")),
),
)
dvr := bsonrw.NewBSONDocumentReader(b)
dvr := bsonrw.NewValueReader(b)
dr, err := dvr.ReadDocument()
noerr(t, err)
_, vr, err := dr.ReadElement()
Expand Down Expand Up @@ -2488,7 +2488,7 @@ func TestDefaultValueDecoders(t *testing.T) {
noerr(t, err)
doc, err = bsoncore.AppendDocumentEnd(doc, idx)
noerr(t, err)
dvr := bsonrw.NewBSONDocumentReader(doc)
dvr := bsonrw.NewValueReader(doc)
noerr(t, err)
dr, err := dvr.ReadDocument()
noerr(t, err)
Expand Down Expand Up @@ -3132,7 +3132,7 @@ func TestDefaultValueDecoders(t *testing.T) {
t.Run("Decode", func(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
vr := bsonrw.NewBSONDocumentReader(tc.b)
vr := bsonrw.NewValueReader(tc.b)
reg := buildDefaultRegistry()
vtype := reflect.TypeOf(tc.value)
dec, err := reg.LookupDecoder(vtype)
Expand Down Expand Up @@ -3181,7 +3181,7 @@ func TestDefaultValueDecoders(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
vr := bsonrw.NewBSONDocumentReader(tc.b)
vr := bsonrw.NewValueReader(tc.b)
reg := buildDefaultRegistry()
vtype := reflect.TypeOf(tc.value)
dec, err := reg.LookupDecoder(vtype)
Expand Down Expand Up @@ -3403,7 +3403,7 @@ func TestDefaultValueDecoders(t *testing.T) {
})
t.Run("top level document", func(t *testing.T) {
data := bsoncore.BuildDocument(nil, bsoncore.AppendDoubleElement(nil, "pi", 3.14159))
vr := bsonrw.NewBSONDocumentReader(data)
vr := bsonrw.NewValueReader(data)
want := primitive.D{{"pi", 3.14159}}
var got interface{}
val := reflect.ValueOf(&got).Elem()
Expand Down Expand Up @@ -3451,7 +3451,7 @@ func TestDefaultValueDecoders(t *testing.T) {
}
for _, tc := range testCases {
var got interface{}
vr := bsonrw.NewBSONDocumentReader(doc)
vr := bsonrw.NewValueReader(doc)
val := reflect.ValueOf(&got).Elem()

err := defaultEmptyInterfaceCodec.DecodeValue(DecodeContext{Registry: tc.registry}, vr, val)
Expand Down Expand Up @@ -3487,7 +3487,7 @@ func TestDefaultValueDecoders(t *testing.T) {
}

var got primitive.D
vr := bsonrw.NewBSONDocumentReader(doc)
vr := bsonrw.NewValueReader(doc)
val := reflect.ValueOf(&got).Elem()
err := defaultSliceCodec.DecodeValue(DecodeContext{Registry: reg}, vr, val)
noerr(t, err)
Expand Down Expand Up @@ -3577,7 +3577,7 @@ func TestDefaultValueDecoders(t *testing.T) {
// DecodeValue error when decoding into a primitive.D.
"primitive.D slice",
primitive.D{},
bsonrw.NewBSONDocumentReader(docBytes),
bsonrw.NewValueReader(docBytes),
emptyInterfaceErrorRegistry,
defaultSliceCodec,
docEmptyInterfaceErr,
Expand All @@ -3600,7 +3600,7 @@ func TestDefaultValueDecoders(t *testing.T) {
// the decodeD helper function.
"primitive.D array",
[1]primitive.E{},
bsonrw.NewBSONDocumentReader(docBytes),
bsonrw.NewValueReader(docBytes),
emptyInterfaceErrorRegistry,
ValueDecoderFunc(dvd.ArrayDecodeValue),
docEmptyInterfaceErr,
Expand All @@ -3623,7 +3623,7 @@ func TestDefaultValueDecoders(t *testing.T) {
// DecodeValue error when decoding into a map.
"map",
map[string]interface{}{},
bsonrw.NewBSONDocumentReader(docBytes),
bsonrw.NewValueReader(docBytes),
emptyInterfaceErrorRegistry,
defaultMapCodec,
docEmptyInterfaceErr,
Expand All @@ -3632,7 +3632,7 @@ func TestDefaultValueDecoders(t *testing.T) {
// DecodeValue error when decoding into a struct.
"struct - DecodeValue error",
emptyInterfaceStruct{},
bsonrw.NewBSONDocumentReader(docBytes),
bsonrw.NewValueReader(docBytes),
emptyInterfaceErrorRegistry,
defaultTestStructCodec,
emptyInterfaceStructErr,
Expand All @@ -3643,15 +3643,15 @@ func TestDefaultValueDecoders(t *testing.T) {
// no decoder for strings.
"struct - no decoder found",
stringStruct{},
bsonrw.NewBSONDocumentReader(docBytes),
bsonrw.NewValueReader(docBytes),
NewRegistryBuilder().Build(),
defaultTestStructCodec,
stringStructErr,
},
{
"deeply nested struct",
outer{},
bsonrw.NewBSONDocumentReader(outerDoc),
bsonrw.NewValueReader(outerDoc),
nestedRegistry,
defaultTestStructCodec,
nestedErr,
Expand Down Expand Up @@ -3681,7 +3681,7 @@ func TestDefaultValueDecoders(t *testing.T) {
type outer struct{ Foo inner }

dc := DecodeContext{Registry: buildDefaultRegistry()}
vr := bsonrw.NewBSONDocumentReader(outerBytes)
vr := bsonrw.NewValueReader(outerBytes)
val := reflect.New(reflect.TypeOf(outer{})).Elem()
err := defaultTestStructCodec.DecodeValue(dc, vr, val)

Expand Down Expand Up @@ -3714,7 +3714,7 @@ func TestDefaultValueDecoders(t *testing.T) {
reg := rb.RegisterTypeMapEntry(bsontype.Boolean, reflect.TypeOf(mybool(true))).Build()

dc := DecodeContext{Registry: reg}
vr := bsonrw.NewBSONDocumentReader(docBytes)
vr := bsonrw.NewValueReader(docBytes)
val := reflect.New(tD).Elem()
err := defaultValueDecoders.DDecodeValue(dc, vr, val)
assert.Nil(t, err, "DDecodeValue error: %v", err)
Expand All @@ -3733,7 +3733,7 @@ func TestDefaultValueDecoders(t *testing.T) {

type myMap map[string]mybool
dc := DecodeContext{Registry: buildDefaultRegistry()}
vr := bsonrw.NewBSONDocumentReader(docBytes)
vr := bsonrw.NewValueReader(docBytes)
val := reflect.New(reflect.TypeOf(myMap{})).Elem()
err := defaultMapCodec.DecodeValue(dc, vr, val)
assert.Nil(t, err, "DecodeValue error: %v", err)
Expand Down
6 changes: 2 additions & 4 deletions bson/bsoncodec/default_value_encoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1770,8 +1770,7 @@ func TestDefaultValueEncoders(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
b := make(bsonrw.SliceWriter, 0, 512)
vw, err := bsonrw.NewBSONValueWriter(&b)
noerr(t, err)
vw := bsonrw.NewValueWriter(&b)
reg := buildDefaultRegistry()
enc, err := reg.LookupEncoder(reflect.TypeOf(tc.value))
noerr(t, err)
Expand Down Expand Up @@ -1821,8 +1820,7 @@ func TestDefaultValueEncoders(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
b := make(bsonrw.SliceWriter, 0, 512)
vw, err := bsonrw.NewBSONValueWriter(&b)
noerr(t, err)
vw := bsonrw.NewValueWriter(&b)
reg := buildDefaultRegistry()
enc, err := reg.LookupEncoder(reflect.TypeOf(tc.value))
noerr(t, err)
Expand Down
14 changes: 4 additions & 10 deletions bson/bsoncodec/registry_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,10 @@ func ExampleRegistry_customEncoder() {
// Marshal the document as BSON. Expect that the int field is encoded to the
// same value and that the negatedInt field is encoded as the negated value.
buf := new(bytes.Buffer)
vw, err := bsonrw.NewBSONValueWriter(buf)
if err != nil {
panic(err)
}
vw := bsonrw.NewValueWriter(buf)
enc := bson.NewEncoder(vw)
enc.SetRegistry(reg)
err = enc.Encode(doc)
err := enc.Encode(doc)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -209,13 +206,10 @@ func ExampleRegistry_RegisterKindEncoder() {
// Marshal the document as BSON. Expect that all fields are encoded as BSON
// int64 (represented as "$numberLong" when encoded as Extended JSON).
buf := new(bytes.Buffer)
vw, err := bsonrw.NewBSONValueWriter(buf)
if err != nil {
panic(err)
}
vw := bsonrw.NewValueWriter(buf)
enc := bson.NewEncoder(vw)
enc.SetRegistry(reg)
err = enc.Encode(doc)
err := enc.Encode(doc)
if err != nil {
panic(err)
}
Expand Down
8 changes: 2 additions & 6 deletions bson/bsonrw/extjson_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,11 @@ type extJSONValueWriter struct {
}

// NewExtJSONValueWriter creates a ValueWriter that writes Extended JSON to w.
func NewExtJSONValueWriter(w io.Writer, canonical, escapeHTML bool) (ValueWriter, error) {
if w == nil {
return nil, errNilWriter
}

func NewExtJSONValueWriter(w io.Writer, canonical, escapeHTML bool) ValueWriter {
// Enable newlines for all Extended JSON value writers created by NewExtJSONValueWriter. We
// expect these value writers to be used with an Encoder, which should add newlines after
// encoded Extended JSON documents.
return newExtJSONWriter(w, canonical, escapeHTML, true), nil
return newExtJSONWriter(w, canonical, escapeHTML, true)
}

func newExtJSONWriter(w io.Writer, canonical, escapeHTML, newlines bool) *extJSONValueWriter {
Expand Down
18 changes: 9 additions & 9 deletions bson/bsonrw/extjson_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package bsonrw

import (
"fmt"
"io/ioutil"
"io"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestExtJSONValueWriter(t *testing.T) {
t.Fatalf("fn must have one return value and it must be an error.")
}
params := make([]reflect.Value, 1, len(tc.params)+1)
ejvw := newExtJSONWriter(ioutil.Discard, true, true, false)
ejvw := newExtJSONWriter(io.Discard, true, true, false)
params[0] = reflect.ValueOf(ejvw)
for _, param := range tc.params {
params = append(params, reflect.ValueOf(param))
Expand All @@ -162,7 +162,7 @@ func TestExtJSONValueWriter(t *testing.T) {
}

t.Run("WriteArray", func(t *testing.T) {
ejvw := newExtJSONWriter(ioutil.Discard, true, true, false)
ejvw := newExtJSONWriter(io.Discard, true, true, false)
ejvw.push(mArray)
want := TransitionError{current: mArray, destination: mArray, parent: mTopLevel,
name: "WriteArray", modes: []mode{mElement, mValue}, action: "write"}
Expand All @@ -172,7 +172,7 @@ func TestExtJSONValueWriter(t *testing.T) {
}
})
t.Run("WriteCodeWithScope", func(t *testing.T) {
ejvw := newExtJSONWriter(ioutil.Discard, true, true, false)
ejvw := newExtJSONWriter(io.Discard, true, true, false)
ejvw.push(mArray)
want := TransitionError{current: mArray, destination: mCodeWithScope, parent: mTopLevel,
name: "WriteCodeWithScope", modes: []mode{mElement, mValue}, action: "write"}
Expand All @@ -182,7 +182,7 @@ func TestExtJSONValueWriter(t *testing.T) {
}
})
t.Run("WriteDocument", func(t *testing.T) {
ejvw := newExtJSONWriter(ioutil.Discard, true, true, false)
ejvw := newExtJSONWriter(io.Discard, true, true, false)
ejvw.push(mArray)
want := TransitionError{current: mArray, destination: mDocument, parent: mTopLevel,
name: "WriteDocument", modes: []mode{mElement, mValue, mTopLevel}, action: "write"}
Expand All @@ -192,7 +192,7 @@ func TestExtJSONValueWriter(t *testing.T) {
}
})
t.Run("WriteDocumentElement", func(t *testing.T) {
ejvw := newExtJSONWriter(ioutil.Discard, true, true, false)
ejvw := newExtJSONWriter(io.Discard, true, true, false)
ejvw.push(mElement)
want := TransitionError{current: mElement,
destination: mElement,
Expand All @@ -206,7 +206,7 @@ func TestExtJSONValueWriter(t *testing.T) {
}
})
t.Run("WriteDocumentEnd", func(t *testing.T) {
ejvw := newExtJSONWriter(ioutil.Discard, true, true, false)
ejvw := newExtJSONWriter(io.Discard, true, true, false)
ejvw.push(mElement)
want := fmt.Errorf("incorrect mode to end document: %s", mElement)
got := ejvw.WriteDocumentEnd()
Expand All @@ -215,7 +215,7 @@ func TestExtJSONValueWriter(t *testing.T) {
}
})
t.Run("WriteArrayElement", func(t *testing.T) {
ejvw := newExtJSONWriter(ioutil.Discard, true, true, false)
ejvw := newExtJSONWriter(io.Discard, true, true, false)
ejvw.push(mElement)
want := TransitionError{current: mElement,
destination: mValue,
Expand All @@ -229,7 +229,7 @@ func TestExtJSONValueWriter(t *testing.T) {
}
})
t.Run("WriteArrayEnd", func(t *testing.T) {
ejvw := newExtJSONWriter(ioutil.Discard, true, true, false)
ejvw := newExtJSONWriter(io.Discard, true, true, false)
ejvw.push(mElement)
want := fmt.Errorf("incorrect mode to end array: %s", mElement)
got := ejvw.WriteArrayEnd()
Expand Down
4 changes: 2 additions & 2 deletions bson/bsonrw/value_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ type valueReader struct {
frame int64
}

// NewBSONDocumentReader returns a ValueReader using b for the underlying BSON
// NewValueReader returns a ValueReader using b for the underlying BSON
// representation. Parameter b must be a BSON Document.
func NewBSONDocumentReader(b []byte) ValueReader {
func NewValueReader(b []byte) ValueReader {
// TODO(skriptble): There's a lack of symmetry between the reader and writer, since the reader takes a []byte while the
// TODO writer takes an io.Writer. We should have two versions of each, one that takes a []byte and one that takes an
// TODO io.Reader or io.Writer. The []byte version will need to return a thing that can return the finished []byte since
Expand Down
Loading

0 comments on commit 25368d6

Please sign in to comment.