Skip to content

Commit

Permalink
Merge branch 'master' into GODRIVER-3090
Browse files Browse the repository at this point in the history
  • Loading branch information
timothy-kim-mongo authored Jul 11, 2024
2 parents 8b0fffb + b79eac4 commit 2a5d78b
Show file tree
Hide file tree
Showing 173 changed files with 3,417 additions and 4,763 deletions.
43 changes: 34 additions & 9 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@ axes:
- id: "windows-64-go-1-20"
display_name: "Windows 64-bit"
run_on:
- windows-vsCurrent-latest-small
- windows-vsCurrent-small
variables:
GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin"
GO_DIST: "C:\\golang\\go1.20"
Expand All @@ -2035,7 +2035,7 @@ axes:
- id: "windows-64-go-1-20"
display_name: "Windows 64-bit"
run_on:
- windows-vsCurrent-latest-small
- windows-vsCurrent-small
variables:
GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin"
GO_DIST: "C:\\golang\\go1.20"
Expand Down Expand Up @@ -2067,7 +2067,7 @@ axes:
- id: "windows-64-vsCurrent-latest-small-go-1-20"
display_name: "Windows 64-bit"
run_on:
- windows-vsCurrent-latest-small
- windows-vsCurrent-small
variables:
GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin"
GO_DIST: "C:\\golang\\go1.20"
Expand Down Expand Up @@ -2388,23 +2388,48 @@ buildvariants:
tasks:
- name: "test-docker-runner"

- matrix_name: "tests-36-with-zlib-support"
- matrix_name: "tests-rhel-36-with-zlib-support"
tags: ["pullrequest"]
matrix_spec: { version: ["3.6"], os-ssl-32: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
matrix_spec: { version: ["3.6"], os-ssl-32: ["rhel87-64-go-1-20"] }
display_name: "${version} ${os-ssl-32}"
tasks:
- name: ".test !.enterprise-auth !.snappy !.zstd"

- matrix_name: "tests-40-with-zlib-support"
- matrix_name: "tests-windows-36-with-zlib-support"
matrix_spec: { version: ["3.6"], os-ssl-32: ["windows-64-go-1-20"] }
display_name: "${version} ${os-ssl-32}"
tasks:
- name: ".test !.enterprise-auth !.snappy !.zstd"

- matrix_name: "tests-rhel-40-with-zlib-support"
tags: ["pullrequest"]
matrix_spec: { version: ["4.0"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
matrix_spec: { version: ["4.0"], os-ssl-40: ["rhel87-64-go-1-20"] }
display_name: "${version} ${os-ssl-40}"
tasks:
- name: ".test !.enterprise-auth !.snappy !.zstd"

- matrix_name: "tests-42-plus-zlib-zstd-support"
- matrix_name: "tests-windows-40-with-zlib-support"
matrix_spec: { version: ["4.0"], os-ssl-40: ["windows-64-go-1-20"] }
display_name: "${version} ${os-ssl-40}"
tasks:
- name: ".test !.enterprise-auth !.snappy !.zstd"

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

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

- matrix_name: "tests-windows-80-zlib-zstd-support"
tags: ["pullrequest"]
matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
matrix_spec: { version: ["8.0"], os-ssl-40: ["windows-64-go-1-20"] }
display_name: "${version} ${os-ssl-40}"
tasks:
- name: ".test !.enterprise-auth !.snappy"
Expand Down
29 changes: 7 additions & 22 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,13 @@ on:

jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
name: Analyze (go)
runs-on: 'ubuntu-latest'
timeout-minutes: 360
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: go
build-mode: manual

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -44,15 +30,14 @@ jobs:
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
languages: go
build-mode: manual

- if: matrix.build-mode == 'manual'
shell: bash
- shell: bash
run: |
make build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
category: "/language:go"
88 changes: 88 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: "The new version to set"
required: true
prev_version:
description: "The previous tagged version"
required: true
push_changes:
description: "Push changes?"
default: true
type: boolean

defaults:
run:
shell: bash -eux {0}

env:
# Changes per branch
SILK_ASSET_GROUP: mongodb-go-driver
EVERGREEN_PROJECT: mongo-go-driver

jobs:
pre-publish:
environment: release
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
outputs:
prev_version: ${{ steps.pre-publish.outputs.prev_version }}
steps:
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
with:
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: mongodb-labs/drivers-github-tools/setup@v2
with:
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
aws_region_name: ${{ vars.AWS_REGION_NAME }}
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
- name: Pre Publish
id: pre-publish
uses: mongodb-labs/drivers-github-tools/golang/pre-publish@v2
with:
version: ${{ inputs.version }}
push_changes: ${{ inputs.push_changes }}

static-scan:
needs: [pre-publish]
permissions:
security-events: write
uses: ./.github/workflows/codeql.yml
with:
ref: ${{ github.ref }}

publish:
needs: [pre-publish, static-scan]
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
contents: write
security-events: read
steps:
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
with:
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: mongodb-labs/drivers-github-tools/setup@v2
with:
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
aws_region_name: ${{ vars.AWS_REGION_NAME }}
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
- name: Publish
uses: mongodb-labs/drivers-github-tools/golang/publish@v2
with:
version: ${{ inputs.version }}
silk_asset_group: ${{ env.SILK_ASSET_GROUP }}
evergreen_project: ${{ env.EVERGREEN_PROJECT }}
prev_version: ${{ inputs.prev_version }}
push_changes: ${{ inputs.push_changes }}
token: ${{ env.GH_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected].0
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected].1
21 changes: 4 additions & 17 deletions bson/array_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,11 @@ import (
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)

// ArrayCodec is the Codec used for bsoncore.Array values.
//
// Deprecated: Use [go.mongodb.org/mongo-driver/bson.NewRegistry] to get a registry with the
// ArrayCodec registered.
type ArrayCodec struct{}

var defaultArrayCodec = NewArrayCodec()

// NewArrayCodec returns an ArrayCodec.
//
// Deprecated: Use [go.mongodb.org/mongo-driver/bson.NewRegistry] to get a registry with the
// ArrayCodec registered.
func NewArrayCodec() *ArrayCodec {
return &ArrayCodec{}
}
// arrayCodec is the Codec used for bsoncore.Array values.
type arrayCodec struct{}

// EncodeValue is the ValueEncoder for bsoncore.Array values.
func (ac *ArrayCodec) EncodeValue(_ EncodeContext, vw ValueWriter, val reflect.Value) error {
func (ac *arrayCodec) EncodeValue(_ EncodeContext, vw ValueWriter, val reflect.Value) error {
if !val.IsValid() || val.Type() != tCoreArray {
return ValueEncoderError{Name: "CoreArrayEncodeValue", Types: []reflect.Type{tCoreArray}, Received: val}
}
Expand All @@ -39,7 +26,7 @@ func (ac *ArrayCodec) EncodeValue(_ EncodeContext, vw ValueWriter, val reflect.V
}

// DecodeValue is the ValueDecoder for bsoncore.Array values.
func (ac *ArrayCodec) DecodeValue(_ DecodeContext, vr ValueReader, val reflect.Value) error {
func (ac *arrayCodec) DecodeValue(_ DecodeContext, vr ValueReader, val reflect.Value) error {
if !val.CanSet() || val.Type() != tCoreArray {
return ValueDecoderError{Name: "CoreArrayDecodeValue", Types: []reflect.Type{tCoreArray}, Received: val}
}
Expand Down
40 changes: 31 additions & 9 deletions bson/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"go.mongodb.org/mongo-driver/bson/bsonoptions"
"go.mongodb.org/mongo-driver/internal/assert"
"go.mongodb.org/mongo-driver/internal/require"
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
Expand Down Expand Up @@ -297,6 +296,30 @@ func TestD(t *testing.T) {
})
}

func TestDStringer(t *testing.T) {
got := D{{"a", 1}, {"b", 2}}.String()
want := `{"a":{"$numberInt":"1"},"b":{"$numberInt":"2"}}`
assert.Equal(t, want, got, "expected: %s, got: %s", want, got)
}

func TestMStringer(t *testing.T) {
type msg struct {
A json.RawMessage `json:"a"`
B json.RawMessage `json:"b"`
}

var res msg
got := M{"a": 1, "b": 2}.String()
err := json.Unmarshal([]byte(got), &res)
require.NoError(t, err, "Unmarshal error")

want := msg{
A: json.RawMessage(`{"$numberInt":"1"}`),
B: json.RawMessage(`{"$numberInt":"2"}`),
}

assert.Equal(t, want, res, "returned string did not unmarshal to the expected document, returned string: %s", got)
}
func TestD_MarshalJSON(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -521,19 +544,18 @@ func TestMapCodec(t *testing.T) {
strstr := stringerString("foo")
mapObj := map[stringerString]int{strstr: 1}
testCases := []struct {
name string
opts *bsonoptions.MapCodecOptions
key string
name string
mapCodec *mapCodec
key string
}{
{"default", bsonoptions.MapCodec(), "foo"},
{"true", bsonoptions.MapCodec().SetEncodeKeysWithStringer(true), "bar"},
{"false", bsonoptions.MapCodec().SetEncodeKeysWithStringer(false), "foo"},
{"default", &mapCodec{}, "foo"},
{"true", &mapCodec{encodeKeysWithStringer: true}, "bar"},
{"false", &mapCodec{encodeKeysWithStringer: false}, "foo"},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
mapCodec := NewMapCodec(tc.opts)
mapRegistry := NewRegistry()
mapRegistry.RegisterKindEncoder(reflect.Map, mapCodec)
mapRegistry.RegisterKindEncoder(reflect.Map, tc.mapCodec)
buf := new(bytes.Buffer)
vw := NewValueWriter(buf)
enc := NewEncoder(vw)
Expand Down
2 changes: 1 addition & 1 deletion bson/bsoncodec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func ExampleValueEncoder() {
var _ ValueEncoderFunc = func(ec EncodeContext, vw ValueWriter, val reflect.Value) error {
var _ ValueEncoderFunc = func(_ EncodeContext, vw ValueWriter, val reflect.Value) error {
if val.Kind() != reflect.String {
return ValueEncoderError{Name: "StringEncodeValue", Kinds: []reflect.Kind{reflect.String}, Received: val}
}
Expand Down
49 changes: 0 additions & 49 deletions bson/bsonoptions/byte_slice_codec_options.go

This file was deleted.

Loading

0 comments on commit 2a5d78b

Please sign in to comment.