Skip to content

Commit

Permalink
Merge branch 'v1' into GODRIVER-2649
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Nov 1, 2023
2 parents 9208f05 + 4f44ebf commit 50f60de
Show file tree
Hide file tree
Showing 99 changed files with 1,654 additions and 357 deletions.
1 change: 1 addition & 0 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@ tasks:
- func: run-atlas-data-lake-test

- name: test-docker-runner
tags: ["pullrequest"]
commands:
- func: run-docker-test

Expand Down
2 changes: 1 addition & 1 deletion .evergreen/ocsp-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
asn1crypto==1.3.0
bottle==0.12.20
oscrypto==1.2.0
oscrypto==1.2.0
3 changes: 1 addition & 2 deletions .evergreen/run-fuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ do
for CORPUS_FILE in $PARENTDIR/testdata/fuzz/$FUNC/*
do
# Check to see if the value for CORPUS_FILE is in cset.
if [[ ! " ${cset[@]} " =~ " ${CORPUS_FILE} " ]]; then
if [[ ! " ${cset[*]} " =~ " ${CORPUS_FILE} " ]]; then
# Create the directory if it doesn't exist.
if [ ! -d $PROJECT_DIRECTORY/fuzz/$FUNC ]; then
mkdir -p $PROJECT_DIRECTORY/fuzz/$FUNC
Expand All @@ -69,4 +69,3 @@ if [ -d $PROJECT_DIRECTORY/fuzz ]; then
# This will trigger a notification to be sent to the Go Driver team.
exit 1
fi

4 changes: 2 additions & 2 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export GOCACHE="$(pwd)/.cache"
export DRIVERS_TOOLS=${DRIVERS_TOOLS:-""}

if [ -z $DRIVERS_TOOLS ]; then
export DRIVERS_TOOLS=="$(dirname $(dirname $(dirname `pwd`)))/drivers-tools"
export DRIVERS_TOOLS="$(dirname $(dirname $(dirname `pwd`)))/drivers-tools"
fi

if [ "Windows_NT" = "$OS" ]; then
Expand Down Expand Up @@ -49,7 +49,7 @@ fi
# Using python3-venv in Ubuntu 14.04 (an OS required for legacy server version
# tasks) requires the use of apt-get, which we wish to avoid. So, we do not set
# a python3 binary on Ubuntu 14.04. Setting AWS temp credentials for legacy
# server version tasks is unneccesary, as temp credentials are only needed on 4.2+.
# server version tasks is unnecessary, as temp credentials are only needed on 4.2+.
if [ ! -z ${PYTHON3_BINARY} ]; then
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: GoDriver Tests

on:
push:
pull_request:

concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true

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

jobs:
pre_commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: pre-commit/action@v3.0.0
50 changes: 50 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-json
- id: end-of-file-fixer
exclude: ^vendor/
exclude_types: [json,yaml]
- id: trailing-whitespace
exclude: ^(vendor/|internal/assert/assertions_test.go)
exclude_types: [json,yaml]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
exclude: ^vendor/

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.0
hooks:
- id: check-github-workflows

# We use the Python version instead of the original version which seems to require Docker
# https://github.com/koalaman/shellcheck-precommit
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.6
hooks:
- id: shellcheck
name: shellcheck
args: ["--severity=error"]

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
hooks:
- id: codespell
args: ["-L", "te,fo,fle,alo,nin,compres,wil,collone,asess,sav,ot,wll,dne,nulll,hellow"]
exclude: ^(vendor/|benchmark/operation_test.go)
exclude_types: [json,yaml,pem]

- repo: https://github.com/golangci/golangci-lint
rev: v1.55.1
hooks:
- id: golangci-lint
18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,28 @@ RUN cd /root && bash ./install-libmongocrypt.sh
# from the libmongocrypt build stage.
FROM drivers-evergreen-tools

# Install common deps.
RUN export DEBIAN_FRONTEND=noninteractive && \
export TZ=Etc/UTC && \
apt-get -qq update && \
apt-get -qqy install --no-install-recommends \
pkg-config \
apt-get -qqy install --reinstall --no-install-recommends \
tzdata \
ca-certificates \
pkg-config \
software-properties-common \
gpg \
apt-utils \
libc6-dev \
gcc \
make && \
apt-add-repository ppa:longsleep/golang-backports && \
sudo update-ca-certificates && \
rm -rf /var/lib/apt/lists/*

# Install golang from the golang-backports ppa.
RUN export DEBIAN_FRONTEND=noninteractive && \
export TZ=Etc/UTC && \
export LC_ALL=C.UTF-8 && \
sudo -E apt-add-repository "ppa:longsleep/golang-backports" && \
apt-get -qq update && \
apt-get -qqy install --no-install-recommends golang-go && \
rm -rf /var/lib/apt/lists/*
Expand Down
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@

The MongoDB supported driver for Go.

-------------------------
______________________________________________________________________

## Requirements

- Go 1.13 or higher. We aim to support the latest versions of Go.
- `go mod tidy` will error when importing the Go Driver using Go versions older than 1.15 due to dependencies that import [io/fs](https://pkg.go.dev/io/fs). See golang/go issue [#44557](https://github.com/golang/go/issues/44557) for more information.
- Go 1.20 or higher is required to run the driver test suite.
- MongoDB 3.6 and higher.

-------------------------
______________________________________________________________________

## Installation

The recommended way to get started using the MongoDB Go driver is by using Go modules to install the dependency in
Expand All @@ -35,7 +37,8 @@ When using a version of Go that does not support modules, the driver can be inst
dep ensure -add "go.mongodb.org/mongo-driver/mongo"
```

-------------------------
______________________________________________________________________

## Usage

To get started with the driver, import the `mongo` package and create a `mongo.Client` with the `Connect` function:
Expand Down Expand Up @@ -150,13 +153,13 @@ Additional examples and documentation can be found under the examples directory

### Network Compression

Network compression will reduce bandwidth requirements between MongoDB and the application.
Network compression will reduce bandwidth requirements between MongoDB and the application.

The Go Driver supports the following compression algorithms:

1. [Snappy](https://google.github.io/snappy/) (`snappy`): available in MongoDB 3.4 and later.
2. [Zlib](https://zlib.net/) (`zlib`): available in MongoDB 3.6 and later.
3. [Zstandard](https://github.com/facebook/zstd/) (`zstd`): available in MongoDB 4.2 and later.
1. [Zlib](https://zlib.net/) (`zlib`): available in MongoDB 3.6 and later.
1. [Zstandard](https://github.com/facebook/zstd/) (`zstd`): available in MongoDB 4.2 and later.

#### Specify Compression Algorithms

Expand All @@ -176,35 +179,41 @@ If compressors are set, the Go Driver negotiates with the server to select the f

Messages compress when both parties enable network compression; otherwise, messages remain uncompressed

-------------------------
______________________________________________________________________

## Feedback

For help with the driver, please post in the [MongoDB Community Forums](https://developer.mongodb.com/community/forums/tag/golang/).

New features and bugs can be reported on jira: https://jira.mongodb.org/browse/GODRIVER

-------------------------
______________________________________________________________________

## Contribution

Check out the [project page](https://jira.mongodb.org/browse/GODRIVER) for tickets that need completing. See our [contribution guidelines](docs/CONTRIBUTING.md) for details.

-------------------------
______________________________________________________________________

## Continuous Integration

Commits to master are run automatically on [evergreen](https://evergreen.mongodb.com/waterfall/mongo-go-driver).

-------------------------
______________________________________________________________________

## Frequently Encountered Issues

See our [common issues](docs/common-issues.md) documentation for troubleshooting frequently encountered issues.

-------------------------
______________________________________________________________________

## Thanks and Acknowledgement

- The Go Gopher artwork by [@ashleymcnamara](https://github.com/ashleymcnamara)
- The original Go Gopher was designed by [Renee French](http://reneefrench.blogspot.com/)

-------------------------
______________________________________________________________________

## License

The MongoDB Go Driver is licensed under the [Apache License](LICENSE).
6 changes: 3 additions & 3 deletions THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ Copyright (c) 2010-2013 - Gustavo Niemeyer <gustavo@niemeyer.net>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand Down
2 changes: 1 addition & 1 deletion bson/bsoncodec/default_value_decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

var (
defaultValueDecoders DefaultValueDecoders
errCannotTruncate = errors.New("float64 can only be truncated to an integer type when truncation is enabled")
errCannotTruncate = errors.New("float64 can only be truncated to a lower precision type when truncation is enabled")
)

type decodeBinaryError struct {
Expand Down
2 changes: 1 addition & 1 deletion bson/bsonrw/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c Copier) CopyBytesToDocumentWriter(dst DocumentWriter, src []byte) error
}

func (c Copier) copyBytesToValueWriter(src []byte, wef writeElementFn) error {
// TODO(skriptble): Create errors types here. Anything thats a tag should be a property.
// TODO(skriptble): Create errors types here. Anything that is a tag should be a property.
length, rem, ok := bsoncore.ReadLength(src)
if !ok {
return fmt.Errorf("couldn't read length from src, not enough bytes. length=%d", len(src))
Expand Down
6 changes: 3 additions & 3 deletions bson/mgocompat/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,13 @@ func TestUnmarshalAllItemsWithPtrSetter(t *testing.T) {
if i == 0 {
assert.Nil(t, field, "expected field to be nil, got: %v", field)
} else {
assert.Nil(t, field.Received, "expected field.recieved to be nil, got: %v", field.Received)
assert.Nil(t, field.Received, "expected field.received to be nil, got: %v", field.Received)
}
} else {
expected := item.obj.(bson.M)["_"]
assert.NotNil(t, field, "Pointer not initialized (%#v)", expected)

assert.True(t, reflect.DeepEqual(expected, field.Received), "expected field.recieved to be: %v, got: %v", expected, field.Received)
assert.True(t, reflect.DeepEqual(expected, field.Received), "expected field.received to be: %v, got: %v", expected, field.Received)
}
}
})
Expand All @@ -933,7 +933,7 @@ func TestUnmarshalWholeDocumentWithSetter(t *testing.T) {
obj := &setterType{}
err := bson.UnmarshalWithRegistry(Registry, []byte(sampleItems[0].data), obj)
assert.Nil(t, err, "expected nil error, got: %v", err)
assert.True(t, reflect.DeepEqual(bson.M{"hello": "world"}, obj.Received), "expected obj.recieved to be: %v, got: %v", bson.M{"hello": "world"}, obj.Received)
assert.True(t, reflect.DeepEqual(bson.M{"hello": "world"}, obj.Received), "expected obj.received to be: %v, got: %v", bson.M{"hello": "world"}, obj.Received)
}

func TestUnmarshalSetterErrors(t *testing.T) {
Expand Down
28 changes: 24 additions & 4 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The Go Driver team uses GitHub to manage and review all code changes. Patches sh
applicable.

Code should compile and tests should pass under all Go versions which the driver currently supports. Currently the Go Driver supports a minimum version of Go 1.13 and requires Go 1.20 for development. Please run the following Make targets to validate your changes:

- `make fmt`
- `make lint` (requires [golangci-lint](https://github.com/golangci/golangci-lint) and [lll](https://github.com/walle/lll) to be installed and available in the `PATH`)
- `make test`
Expand All @@ -29,6 +30,23 @@ If any tests do not pass, or relevant tests are not included, the patch will not

If you are working on a bug or feature listed in Jira, please include the ticket number prefixed with GODRIVER in the commit message and GitHub pull request title, (e.g. GODRIVER-123). For the patch commit message itself, please follow the [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/) guide.

### Linting on commit

The Go team uses [pre-commit](https://pre-commit.com/#installation) to lint both source and text files.

To install locally, run:

```bash
brew install pre-commit
pre-commit install
```

After that, the checks will run on any changed files when committing. To manually run the checks on all files, run:

```bash
pre-commit run --all-files
```

### Cherry-picking between branches

You must first install the `gh` cli (`brew install gh`), then set your GitHub username:
Expand Down Expand Up @@ -77,6 +95,7 @@ mongod \
```

To run the tests with `make`, set:

- `MONGO_GO_DRIVER_CA_FILE` to the location of the CA file used by the database
- `MONGO_GO_DRIVER_KEY_FILE` to the location of the client key file
- `MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE` to the location of the pkcs8 client key file encrypted with the password string: `password`
Expand All @@ -98,6 +117,7 @@ make
```

Notes:

- The `--tlsAllowInvalidCertificates` flag is required on the server for the test suite to work correctly.
- The test suite requires the auth database to be set with `?authSource=admin`, not `/admin`.

Expand All @@ -120,7 +140,7 @@ The requirements for testing FaaS implementations in the Go Driver vary dependin
The following are the requirements for running the AWS Lambda tests locally:

1. [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html)
2. [Docker](https://www.docker.com/products/docker-desktop/)
1. [Docker](https://www.docker.com/products/docker-desktop/)

Local testing requires exporting the `MONGODB_URI` environment variables. To build the AWS Lambda image and invoke the `MongoDBFunction` lambda function use the `build-faas-awslambda` make target:

Expand All @@ -134,15 +154,15 @@ There is currently no arm64 support for the go1.x runtime, see [here](https://do

### Testing in Docker

We support local testing in Docker. Ensure ``docker`` is installed and running, and then run:
We support local testing in Docker. To test using docker, you will need to set the `DRIVERS_TOOLs` environment variable to point to a local clone of the drivers-evergreen-tools repository. This is essential for running the testing matrix in a container. You can set the `DRIVERS_TOOLS` variable in your shell profile or in your project-specific environment.

```bash
bash etc/run_docker.sh
```

The script takes an optional argument for the ``MAKEFILE_TARGET`` and allows for some environment variable overrides.
The script takes an optional argument for the `MAKEFILE_TARGET` and allows for some environment variable overrides.
The docker container has the required binaries, including libmongocrypt.
The entry script starts a MongoDB topology, and then executes the desired ``MAKEFILE_TARGET``.
The entry script starts a MongoDB topology, and then executes the desired `MAKEFILE_TARGET`.

For example, to test against a sharded cluster, using enterprise auth, run:

Expand Down
1 change: 1 addition & 0 deletions docs/common-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ When connecting to a MongoDB deployment with password authentication enabled, if
> connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.
That error can be caused by a number of issues. The error message intentionally omits the exact authentication failure reason (see the [OWASP Authentication and Error Messages guidelines](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html#authentication-and-error-messages) for an explanation). Possible causes of the error include:

- Incorrect password.
- Incorrect username.
- Incorrect authentication database (i.e. [authSource](https://www.mongodb.com/docs/manual/reference/connection-string/#mongodb-urioption-urioption.authSource)).
Expand Down
Loading

0 comments on commit 50f60de

Please sign in to comment.