Skip to content

Commit 0e82629

Browse files
tfogoskriptble
authored andcommitted
Improve documentation and make commands for tests
Previously the readme said that tests could be run with `make`. This was not the case as a TOPOLOGY variable had to be set. This patch adds a check to ensure that variables used in testing are set to valid values. It also outlines usage of testing variables in the readme. Change-Id: I7f60fb78282f08ca528f64e40b87fed67b5780f7
1 parent 5a92b8c commit 0e82629

File tree

3 files changed

+83
-3
lines changed

3 files changed

+83
-3
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ TEST_PKGS = $(BSON_TEST_PKGS) $(MONGO_TEST_PKGS) $(UNSTABLE_TEST_PKGS) $(TAG_PKG
1414
TEST_TIMEOUT = 600
1515

1616
.PHONY: default
17-
default: check-fmt vet build-examples lint errcheck test-cover test-race
17+
default: check-env check-fmt vet build-examples lint errcheck test-cover test-race
18+
19+
.PHONY: check-env
20+
check-env:
21+
etc/check_env.sh
1822

1923
.PHONY: doc
2024
doc:

README.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,63 @@ New Features and bugs can be reported on jira: https://jira.mongodb.org/browse/G
124124
-------------------------
125125
## Testing / Development
126126

127-
To run driver tests, make sure a MongoDB server instance is running at localhost:27017. Using make, you can run `make` (on windows, run `nmake`).
128-
This will run coverage, run go-lint, run go-vet, and build the examples.
127+
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`) with the following:
128+
129+
```
130+
TOPOLOGY=server make
131+
```
132+
133+
The `TOPOLOGY`variable must be set to run tests. This will run coverage, run go-lint, run go-vet, and build the examples.
134+
135+
### Testing Different Topologies
136+
137+
To test a **replica set**, set `MONGODB_URI="<connection-string>"` and `TOPOLOGY=replica_set` for the `make` command. For example, for a local replica set named `rs1` comprised of three nodes on ports 27017, 27018, and 27019:
138+
139+
```
140+
MONGODB_URI="mongodb://localhost:27017,localhost:27018,localhost:27018/?replicaSet=rs1" TOPOLOGY=replica_set make
141+
```
142+
143+
To test a **sharded cluster**, set `MONGODB_URI="<connection-string>"` and `TOPOLOGY=sharded_cluster` variables for the `make` command. For example, for a sharded cluster with a single mongos on port 27017:
144+
145+
```
146+
MONGODB_URI="mongodb://localhost:27017/" TOPOLOGY=sharder_cluster make
147+
```
148+
149+
### Testing Auth and SSL
150+
151+
To test authentication and SSL, first set up a MongoDB cluster with auth and SSL configured. Testing authentication requires a user with the `root` role on the `admin` database. The Go Driver repository comes with example certificates in the `data/certificates` directory. These certs can be used for testing. Here is an example command that would run a mongod with SSL correctly configured for tests:
152+
153+
```
154+
mongod \
155+
--auth \
156+
--sslMode requireSSL \
157+
--sslPEMKeyFile $(pwd)/data/certificates/server.pem \
158+
--sslCAFile $(pwd)/data/certificates/ca.pem \
159+
--sslWeakCertificateValidation
160+
```
161+
162+
To run the tests with `make`, set `MONGO_GO_DRIVER_CA_FILE` to the location of the CA file used by the database, set `MONGODB_URI` to the connection string of the server, set `AUTH=auth`, and set `SSL=ssl`. For example:
163+
164+
```
165+
AUTH=auth SSL=ssl MONGO_GO_DRIVER_CA_FILE=$(pwd)/data/certificates/ca.pem MONGODB_URI="mongodb://user:password@localhost:27017/?authSource=admin" make
166+
```
167+
168+
Notes:
169+
- The `--sslWeakCertificateValidation` flag is required on the server for the test suite to work correctly.
170+
- The test suite requires the auth database to be set with `?authSource=admin`, not `/admin`.
171+
172+
### Testing Compression
173+
174+
The MongoDB Go Driver supports wire protocol compression using Snappy or zLib. To run tests with wire protocol compression, set `MONGO_GO_DRIVER_COMPRESSOR` to `snappy` or `zlib`. For example:
175+
176+
```
177+
MONGO_GO_DRIVER_COMPRESSOR=snappy make
178+
```
179+
180+
Ensure the [`--networkMessageCompressors` flag](https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-networkmessagecompressors) on mongod or mongos includes `zlib` if testing zLib compression.
181+
182+
-------------------------
183+
## Feedback
129184

130185
The MongoDB Go Driver is not feature complete, so any help is appreciated. Check out the [project page](https://jira.mongodb.org/browse/GODRIVER)
131186
for tickets that need completing. See our [contribution guidelines](CONTRIBUTING.md) for details.

etc/check_env.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
if [[ ! $TOPOLOGY =~ ^(server|replica_set|sharded_cluster)$ ]]; then
4+
>&2 echo "Invalid value of TOPOLOGY. TOPOLOGY must be set to one of: server, replica_set, sharded_cluster"
5+
exit 1
6+
fi
7+
8+
if [ ! -z $AUTH ] && [[ ! $AUTH =~ ^(noauth|auth)$ ]]; then
9+
>&2 echo "Invalid value of AUTH. AUTH can optionally be set to one of: noauth, auth"
10+
exit 1
11+
fi
12+
13+
if [ ! -z $SSL ] && [[ ! $SLL =~ ^(nossl|ssl)$ ]]; then
14+
>&2 echo "Invalid value of SSL. SSL can optionally be set to one of: nossl, ssl"
15+
exit 1
16+
fi
17+
18+
if [ ! -z $MONGO_GO_DRIVER_COMPRESSOR ] && [[ ! $MONGO_GO_DRIVER_COMPRESSOR =~ ^(snappy|zlib)$ ]]; then
19+
>&2 echo "Invalid value of MONGO_GO_DRIVER_COMPRESSOR. MONGO_GO_DRIVER_COMPRESSOR can optionally be set to one of: snappy, zlib"
20+
exit 1
21+
fi

0 commit comments

Comments
 (0)