Skip to content

Commit 3c991a0

Browse files
committed
Merge branch 'v1' of github.com:mongodb/mongo-go-driver into GODRIVER-3008
2 parents 84f14c3 + 6d7a981 commit 3c991a0

File tree

11 files changed

+200
-23
lines changed

11 files changed

+200
-23
lines changed

.evergreen/config.yml

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,10 @@ functions:
9797
go version
9898
go env
9999
100-
LIBMONGOCRYPT_TAG="1.8.0-alpha1"
101-
# Install libmongocrypt based on OS.
100+
# Install libmongocrypt.
101+
bash etc/install-libmongocrypt.sh
102102
if [ "Windows_NT" = "$OS" ]; then
103-
mkdir -p c:/libmongocrypt/include
104-
mkdir -p c:/libmongocrypt/bin
105-
echo "fetching build for Windows ... begin"
106-
mkdir libmongocrypt-all
107-
cd libmongocrypt-all
108-
# The following URL is published from the upload-all task in the libmongocrypt Evergreen project.
109-
curl https://mciuploads.s3.amazonaws.com/libmongocrypt/all/$LIBMONGOCRYPT_TAG/libmongocrypt-all.tar.gz -o libmongocrypt-all.tar.gz
110-
tar -xf libmongocrypt-all.tar.gz
111-
cd ..
112-
cp libmongocrypt-all/windows-test/bin/mongocrypt.dll c:/libmongocrypt/bin
113-
cp libmongocrypt-all/windows-test/include/mongocrypt/*.h c:/libmongocrypt/include
114-
export PATH=$PATH:/cygdrive/c/libmongocrypt/bin
115-
rm -rf libmongocrypt-all
116-
echo "fetching build for Windows ... end"
117-
else
118-
git clone https://github.com/mongodb/libmongocrypt --depth=1 --branch $LIBMONGOCRYPT_TAG
119-
if ! ( ./libmongocrypt/.evergreen/compile.sh >| output.txt 2>&1 ); then
120-
cat output.txt 1>&2
121-
exit 1
122-
fi
103+
export PATH=$PATH:/cygdrive/c/libmongocrypt/bin
123104
fi
124105
125106
cat <<EOT > expansion.yml
@@ -626,6 +607,17 @@ functions:
626607
MONGODB_URI="mongodb://mhuser:pencil@localhost" \
627608
make evg-test-atlas-data-lake
628609
610+
run-docker-test:
611+
- command: shell.exec
612+
type: test
613+
params:
614+
shell: "bash"
615+
working_dir: src/go.mongodb.org/mongo-driver
616+
script: |
617+
${PREPARE_SHELL}
618+
bash etc/run_docker.sh
619+
TOPOLOGY=sharded_cluster bash etc/run_docker.sh test-short
620+
629621
run-valid-ocsp-server:
630622
- command: shell.exec
631623
params:
@@ -1691,6 +1683,10 @@ tasks:
16911683
- func: bootstrap-mongohoused
16921684
- func: run-atlas-data-lake-test
16931685

1686+
- name: test-docker-runner
1687+
commands:
1688+
- func: run-docker-test
1689+
16941690
- name: test-load-balancer-noauth-nossl
16951691
tags: ["load-balancer"]
16961692
commands:
@@ -2731,6 +2727,15 @@ buildvariants:
27312727
tasks:
27322728
- name: "test-atlas-data-lake"
27332729

2730+
- name: docker-runner-test
2731+
display_name: "Docker Runner Test"
2732+
run_on:
2733+
- ubuntu2204-large
2734+
expansions:
2735+
GO_DIST: "/opt/golang/go1.20"
2736+
tasks:
2737+
- name: "test-docker-runner"
2738+
27342739
- matrix_name: "tests-36-with-zlib-support"
27352740
tags: ["pullrequest"]
27362741
matrix_spec: { version: ["3.6"], os-ssl-32: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }

.evergreen/run-tests.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ set -o errexit
44

55
export GOPATH=$(dirname $(dirname $(dirname `pwd`)))
66
export GOCACHE="$(pwd)/.cache"
7-
export DRIVERS_TOOLS="$(dirname $(dirname $(dirname `pwd`)))/drivers-tools"
7+
export DRIVERS_TOOLS=${DRIVERS_TOOLS:-""}
8+
9+
if [ -z $DRIVERS_TOOLS ]; then
10+
export DRIVERS_TOOLS=="$(dirname $(dirname $(dirname `pwd`)))/drivers-tools"
11+
fi
812

913
if [ "Windows_NT" = "$OS" ]; then
1014
export GOPATH=$(cygpath -m $GOPATH)
@@ -14,6 +18,7 @@ fi
1418

1519
export GOROOT="${GOROOT}"
1620
export PATH="${GOROOT}/bin:${GCC_PATH}:$GOPATH/bin:$PATH"
21+
export PATH="${MONGODB_BINARIES:-$DRIVERS_TOOLS/mongodb/bin}:$PATH"
1722
export PROJECT="${project}"
1823
export PKG_CONFIG_PATH=$(pwd)/install/libmongocrypt/lib64/pkgconfig:$(pwd)/install/mongo-c-driver/lib/pkgconfig
1924
export LD_LIBRARY_PATH=$(pwd)/install/libmongocrypt/lib64

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ perf
1212
**mongocryptd.pid
1313
*.test
1414
.DS_Store
15+
install
1516
main.so
1617
.cache
1718
install
1819
libmongocrypt
1920
venv
21+
test.suite
2022

2123
# AWS SAM-generated files
2224
internal/test/faas/awslambda/.aws-sam

Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Dockerfile for Go Driver local development.
2+
3+
# Build libmongocrypt in a separate build stage.
4+
FROM ubuntu:20.04 as libmongocrypt
5+
6+
RUN apt-get -qq update && \
7+
apt-get -qqy install --no-install-recommends \
8+
git \
9+
ca-certificates \
10+
curl \
11+
build-essential \
12+
libssl-dev \
13+
python
14+
15+
COPY etc/install-libmongocrypt.sh /root/install-libmongocrypt.sh
16+
RUN cd /root && bash ./install-libmongocrypt.sh
17+
18+
19+
# Inherit from the drivers-evergreen-tools image and copy in the files
20+
# from the libmongocrypt build stage.
21+
FROM drivers-evergreen-tools
22+
23+
RUN export DEBIAN_FRONTEND=noninteractive && \
24+
export TZ=Etc/UTC && \
25+
apt-get -qq update && \
26+
apt-get -qqy install --no-install-recommends \
27+
pkg-config \
28+
tzdata \
29+
gpg \
30+
apt-utils \
31+
make && \
32+
apt-add-repository ppa:longsleep/golang-backports && \
33+
apt-get -qq update && \
34+
apt-get -qqy install --no-install-recommends golang-go && \
35+
rm -rf /var/lib/apt/lists/*
36+
37+
COPY ./etc/docker_entry.sh /root/docker_entry.sh
38+
39+
COPY --from=libmongocrypt /root/install /root/install
40+
41+
ENTRYPOINT ["/bin/bash", "/root/docker_entry.sh"]

docs/CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ prompt before creating a PR to the target branch.
5151

5252
The driver tests can be run against several database configurations. The most simple configuration is a standalone mongod with no auth, no ssl, and no compression. To run these basic driver tests, make sure a standalone MongoDB server instance is running at localhost:27017. To run the tests, you can run `make` (on Windows, run `nmake`). This will run coverage, run go-lint, run go-vet, and build the examples.
5353

54+
You can install `libmongocrypt` locally by running `bash etc/build-libmongocrypt.sh`, which will create an `install` directory
55+
in the repository top level directory. On Windows you will also need to add `c:/libmongocrypt/` to your `PATH`.
56+
5457
### Testing Different Topologies
5558

5659
To test a **replica set** or **sharded cluster**, set `MONGODB_URI="<connection-string>"` for the `make` command.
@@ -129,6 +132,24 @@ The usage of host.docker.internal comes from the [Docker networking documentatio
129132

130133
There is currently no arm64 support for the go1.x runtime, see [here](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). Known issues running on linux/arm64 include the inability to network with the localhost from the public.ecr.aws/lambda/go Docker image.
131134

135+
### Testing in Docker
136+
137+
We support local testing in Docker. Ensure ``docker`` is installed and running, and then run:
138+
139+
```bash
140+
bash etc/run_docker.sh
141+
```
142+
143+
The script takes an optional argument for the ``MAKEFILE_TARGET`` and allows for some environment variable overrides.
144+
The docker container has the required binaries, including libmongocrypt.
145+
The entry script starts a MongoDB topology, and then executes the desired ``MAKEFILE_TARGET``.
146+
147+
For example, to test against a sharded cluster, using enterprise auth, run:
148+
149+
```bash
150+
TOPOLOGY=sharded_cluster bash etc/run_docker.sh evg-test-enterprise-auth
151+
```
152+
132153
## Talk To Us
133154

134155
If you want to work on the driver, write documentation, or have questions/complaints, please reach out to us either via [MongoDB Community Forums](https://community.mongodb.com/tags/c/drivers-odms-connectors/7/go-driver) or by creating a Question issue in [Jira](https://jira.mongodb.org/secure/CreateIssue!default.jspa).

etc/docker_entry.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Entry point for Dockerfile for launching a server and running a go test.
4+
#
5+
set -eux
6+
7+
# Start the server.
8+
bash /root/base-entrypoint.sh
9+
source $DRIVERS_TOOLS/.evergreen/mo-expansion.sh
10+
11+
# Prep files.
12+
cd /src
13+
rm -f test.suite
14+
cp -r $HOME/install ./install
15+
export PATH="$MONGODB_BINARIES:$PATH"
16+
17+
# Run the test.
18+
bash ./.evergreen/run-tests.sh

etc/install-libmongocrypt.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
# install libmongocrypt
3+
# This script installs libmongocrypt into an "install" directory.
4+
set -eux
5+
6+
LIBMONGOCRYPT_TAG="1.8.2"
7+
8+
# Install libmongocrypt based on OS.
9+
if [ "Windows_NT" = "${OS:-}" ]; then
10+
mkdir -p c:/libmongocrypt/include
11+
mkdir -p c:/libmongocrypt/bin
12+
echo "fetching build for Windows ... begin"
13+
mkdir libmongocrypt-all
14+
cd libmongocrypt-all
15+
# The following URL is published from the upload-all task in the libmongocrypt Evergreen project.
16+
curl https://mciuploads.s3.amazonaws.com/libmongocrypt/all/$LIBMONGOCRYPT_TAG/libmongocrypt-all.tar.gz -o libmongocrypt-all.tar.gz
17+
tar -xf libmongocrypt-all.tar.gz
18+
cd ..
19+
cp libmongocrypt-all/windows-test/bin/mongocrypt.dll c:/libmongocrypt/bin
20+
cp libmongocrypt-all/windows-test/include/mongocrypt/*.h c:/libmongocrypt/include
21+
22+
rm -rf libmongocrypt-all
23+
echo "fetching build for Windows ... end"
24+
else
25+
rm -rf libmongocrypt
26+
git clone https://github.com/mongodb/libmongocrypt --depth=1 --branch $LIBMONGOCRYPT_TAG 2> /dev/null
27+
if ! ( ./libmongocrypt/.evergreen/compile.sh >| output.txt 2>&1 ); then
28+
cat output.txt 1>&2
29+
exit 1
30+
fi
31+
mv output.txt install
32+
rm -rf libmongocrypt
33+
fi

etc/run_docker.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Script to run a test suite in docker locally
4+
set -eux
5+
6+
if [ -z "$DRIVERS_TOOLS" ]; then
7+
echo "Please set DRIVERS_TOOLS env variable."
8+
exit 1
9+
fi
10+
PLATFORM=${DOCKER_PLATFORM:-}
11+
12+
pushd $DRIVERS_TOOLS/.evergreen/docker/ubuntu20.04
13+
docker build $PLATFORM -t drivers-evergreen-tools .
14+
popd
15+
docker build $PLATFORM -t go-test .
16+
17+
# Handle environment variables and optional positional arg for the makefile target.
18+
19+
MAKEFILE_TARGET=${1:-evg-test-versioned-api}
20+
MONGODB_VERSION=${MONGODB_VERSION:-latest}
21+
TOPOLOGY=${TOPOLOGY:-replica_set}
22+
ORCHESTRATION_FILE=${ORCHESTRATION_FILE:-basic.json}
23+
AUTH=${AUTH:-""}
24+
SSL=${SSL:=""}
25+
GO_BUILD_TAGS=${GO_BUILD_TAGS:-""}
26+
27+
ENV="-e MONGODB_VERSION=$MONGODB_VERSION -e TOPOLOGY=$TOPOLOGY"
28+
ENV="$ENV -e MAKEFILE_TARGET=$MAKEFILE_TARGET -e AUTH=$AUTH"
29+
ENV="$ENV -e ORCHESTRATION_FILE=$ORCHESTRATION_FILE -e SSL=$SSL"
30+
ENV="$ENV -e GO_BUILD_TAGS=$GO_BUILD_TAGS"
31+
32+
VOL="-v `pwd`:/src"
33+
VOL="$VOL -v $DRIVERS_TOOLS:/root/drivers-evergreen-tools"
34+
USE_TTY=""
35+
test -t 1 && USE_TTY="-t"
36+
37+
docker run $PLATFORM --rm $VOL $ENV -i $USE_TTY go-test
38+
if [ -f "test.suite" ]; then
39+
tail test.suite
40+
fi

mongo/client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"go.mongodb.org/mongo-driver/mongo/readpref"
2424
"go.mongodb.org/mongo-driver/mongo/writeconcern"
2525
"go.mongodb.org/mongo-driver/tag"
26+
"go.mongodb.org/mongo-driver/x/mongo/driver/mongocrypt"
2627
"go.mongodb.org/mongo-driver/x/mongo/driver/session"
2728
"go.mongodb.org/mongo-driver/x/mongo/driver/topology"
2829
)
@@ -443,6 +444,9 @@ func TestClient(t *testing.T) {
443444
if cryptSharedLibPath == "" {
444445
t.Skip("CRYPT_SHARED_LIB_PATH not set, skipping")
445446
}
447+
if len(mongocrypt.Version()) == 0 {
448+
t.Skip("Not built with cse flag")
449+
}
446450

447451
testCases := []struct {
448452
description string

mongo/integration/handshake_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import (
2525
func TestHandshakeProse(t *testing.T) {
2626
mt := mtest.New(t)
2727

28+
if len(os.Getenv("DOCKER_RUNNING")) > 0 {
29+
t.Skip("These tests gives different results when run in Docker due to extra environment data.")
30+
}
31+
2832
opts := mtest.NewOptions().
2933
CreateCollection(false).
3034
ClientType(mtest.Proxy)

mongo/integration/sdam_prose_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package integration
88

99
import (
1010
"context"
11+
"os"
1112
"runtime"
1213
"testing"
1314
"time"
@@ -52,6 +53,9 @@ func TestSDAMProse(t *testing.T) {
5253
// sent messages. The sleep duration will be at least the specified duration but
5354
// possibly longer, which could lead to extra heartbeat messages, so account for that in
5455
// the assertions.
56+
if len(os.Getenv("DOCKER_RUNNING")) > 0 {
57+
mt.Skip("skipping test in docker environment")
58+
}
5559
start := time.Now()
5660
time.Sleep(2 * time.Second)
5761
messages := mt.GetProxiedMessages()

0 commit comments

Comments
 (0)