From 1dbe6de316e34a16dfa0c11c45b54b0e5dd05cdf Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Tue, 17 Oct 2023 19:25:15 -0600 Subject: [PATCH 1/4] GODRIVER-3013 Resolve race test failures (#1425) --- mongo/integration/unified/logger.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mongo/integration/unified/logger.go b/mongo/integration/unified/logger.go index 1d9a612092..6d5b7efcdc 100644 --- a/mongo/integration/unified/logger.go +++ b/mongo/integration/unified/logger.go @@ -52,6 +52,9 @@ func newLogger(olm *observeLogMessages, bufSize int) *Logger { // Info implements the logger.Sink interface's "Info" method for printing log // messages. func (log *Logger) Info(level int, msg string, args ...interface{}) { + log.orderMu.Lock() + defer log.orderMu.Unlock() + if log.logQueue == nil { return } @@ -62,9 +65,6 @@ func (log *Logger) Info(level int, msg string, args ...interface{}) { return } - log.orderMu.Lock() - defer log.orderMu.Unlock() - defer func() { log.lastOrder++ }() // Add the Diff back to the level, as there is no need to create a From 1066e2a3b56f6ef4ee0a99140ed8814c9d455de9 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 18 Oct 2023 10:08:24 -0500 Subject: [PATCH 2/4] GODRIVER-2607 Remove legacy shell from test scripts (#1429) --- .evergreen/config.yml | 202 +++-------------------------- .evergreen/run-mongodb-aws-test.sh | 15 +-- 2 files changed, 21 insertions(+), 196 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index a54bb5e850..23d02522ee 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -112,6 +112,7 @@ functions: PROJECT_DIRECTORY: "$PROJECT_DIRECTORY" PREPARE_SHELL: | set -o errexit + export SKIP_LEGACY_SHELL=1 export GOROOT="$GOROOT" export GOPATH="$GOPATH" export GOCACHE="$GOCACHE" @@ -724,61 +725,21 @@ functions: fi add-aws-auth-variables-to-file: - - command: shell.exec - type: test + - command: ec2.assume_role params: - shell: "bash" - working_dir: "src" - silent: true - script: | - cat < ${DRIVERS_TOOLS}/.evergreen/auth_aws/aws_e2e_setup.json - { - "iam_auth_ecs_account" : "${iam_auth_ecs_account}", - "iam_auth_ecs_secret_access_key" : "${iam_auth_ecs_secret_access_key}", - "iam_auth_ecs_account_arn": "arn:aws:iam::557821124784:user/authtest_fargate_user", - "iam_auth_ecs_cluster": "${iam_auth_ecs_cluster}", - "iam_auth_ecs_task_definition": "${iam_auth_ecs_task_definition_ubuntu2004}", - "iam_auth_ecs_subnet_a": "${iam_auth_ecs_subnet_a}", - "iam_auth_ecs_subnet_b": "${iam_auth_ecs_subnet_b}", - "iam_auth_ecs_security_group": "${iam_auth_ecs_security_group}", - "iam_auth_assume_aws_account" : "${iam_auth_assume_aws_account}", - "iam_auth_assume_aws_secret_access_key" : "${iam_auth_assume_aws_secret_access_key}", - "iam_auth_assume_role_name" : "${iam_auth_assume_role_name}", - "iam_auth_ec2_instance_account" : "${iam_auth_ec2_instance_account}", - "iam_auth_ec2_instance_secret_access_key" : "${iam_auth_ec2_instance_secret_access_key}", - "iam_auth_ec2_instance_profile" : "${iam_auth_ec2_instance_profile}", - "iam_auth_assume_web_role_name": "${iam_auth_assume_web_role_name}", - "iam_web_identity_issuer": "${iam_web_identity_issuer}", - "iam_web_identity_rsa_key": "${iam_web_identity_rsa_key}", - "iam_web_identity_jwks_uri": "${iam_web_identity_jwks_uri}", - "iam_web_identity_token_file": "${iam_web_identity_token_file}" - } - EOF - - run-aws-auth-test-with-regular-aws-credentials: + role_arn: ${aws_test_secrets_role} - command: shell.exec type: test params: + include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"] shell: "bash" working_dir: "src" script: | ${PREPARE_SHELL} - cd ${DRIVERS_TOOLS}/.evergreen/auth_aws - . ./activate-authawsvenv.sh - mongo aws_e2e_regular_aws.js - - command: shell.exec - type: test - params: - shell: "bash" - working_dir: "src" - silent: true - script: | - cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" - alias urlencode='python3 -c "import sys, urllib.parse as ulp; sys.stdout.write(ulp.quote_plus(sys.argv[1]))"' - USER=$(urlencode ${iam_auth_ecs_account}) - PASS=$(urlencode ${iam_auth_ecs_secret_access_key}) - MONGODB_URI="mongodb://$USER:$PASS@localhost" - EOF + cd $DRIVERS_TOOLS/.evergreen/auth_aws + ./setup_secrets.sh drivers/aws_auth + + run-aws-auth-test-with-regular-aws-credentials: - command: shell.exec type: test params: @@ -786,7 +747,7 @@ functions: working_dir: "src" script: | ${PREPARE_SHELL} - ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh + ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh regular run-aws-auth-test-with-assume-role-credentials: - command: shell.exec @@ -796,36 +757,7 @@ functions: working_dir: "src" script: | ${PREPARE_SHELL} - cd ${DRIVERS_TOOLS}/.evergreen/auth_aws - . ./activate-authawsvenv.sh - mongo aws_e2e_assume_role.js - - command: shell.exec - type: test - params: - shell: "bash" - working_dir: "src" - silent: true - script: | - # DO NOT ECHO WITH XTRACE - cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" - alias urlencode='python3 -c "import sys, urllib.parse as ulp; sys.stdout.write(ulp.quote_plus(sys.argv[1]))"' - alias jsonkey='python3 -c "import json,sys;sys.stdout.write(json.load(sys.stdin)[sys.argv[1]])" < ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json' - USER=$(jsonkey AccessKeyId) - USER=$(urlencode $USER) - PASS=$(jsonkey SecretAccessKey) - PASS=$(urlencode $PASS) - SESSION_TOKEN=$(jsonkey SessionToken) - SESSION_TOKEN=$(urlencode $SESSION_TOKEN) - MONGODB_URI="mongodb://$USER:$PASS@localhost" - EOF - - command: shell.exec - type: test - params: - shell: "bash" - working_dir: "src" - script: | - ${PREPARE_SHELL} - ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh + ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh assume-role run-aws-auth-test-with-aws-EC2-credentials: - command: shell.exec @@ -839,38 +771,9 @@ functions: echo "This platform does not support the EC2 auth test, skipping..." exit 0 fi - cd ${DRIVERS_TOOLS}/.evergreen/auth_aws - . ./activate-authawsvenv.sh - mongo aws_e2e_ec2.js - - command: shell.exec - type: test - params: - shell: "bash" - working_dir: "src" - script: | - ${PREPARE_SHELL} - if [ "${SKIP_EC2_AUTH_TEST}" = "true" ]; then - exit 0 - fi - - # Truncate "prepare_mongodb_aws.sh" to zero length. If file not present, creates zero-length file. - : > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" - - ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh + ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh ec2 run-aws-auth-test-with-aws-credentials-as-environment-variables: - - command: shell.exec - type: test - params: - shell: "bash" - working_dir: "src" - silent: true - script: | - # DO NOT ECHO WITH XTRACE - cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" - export AWS_ACCESS_KEY_ID=${iam_auth_ecs_account} - export AWS_SECRET_ACCESS_KEY=${iam_auth_ecs_secret_access_key} - EOF - command: shell.exec type: test params: @@ -878,23 +781,9 @@ functions: working_dir: "src" script: | ${PREPARE_SHELL} - PROJECT_DIRECTORY=${PROJECT_DIRECTORY} ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh + ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh env-creds run-aws-auth-test-with-aws-credentials-and-session-token-as-environment-variables: - - command: shell.exec - type: test - params: - shell: "bash" - working_dir: "src" - silent: true - script: | - # DO NOT ECHO WITH XTRACE - cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" - alias jsonkey='python -c "import json,sys;sys.stdout.write(json.load(sys.stdin)[sys.argv[1]])" < ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json' - export AWS_ACCESS_KEY_ID=$(jsonkey AccessKeyId) - export AWS_SECRET_ACCESS_KEY=$(jsonkey SecretAccessKey) - export AWS_SESSION_TOKEN=$(jsonkey SessionToken) - EOF - command: shell.exec type: test params: @@ -902,7 +791,7 @@ functions: working_dir: "src" script: | ${PREPARE_SHELL} - ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh + ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh session-creds run-aws-ECS-auth-test: - command: shell.exec @@ -934,14 +823,9 @@ functions: cp ${PROJECT_DIRECTORY}/main $ECS_SRC_DIR cp ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-ecs-test.sh $ECS_SRC_DIR/.evergreen tar -czf $ECS_SRC_DIR/src.tgz -C $PROJECT_DIRECTORY . - cd $AUTH_AWS_DIR - . ./activate-authawsvenv.sh - cat < setup.js - const mongo_binaries = "$MONGODB_BINARIES"; - const project_dir = "$ECS_SRC_DIR"; - EOF - cat setup.js - mongo --nodb setup.js aws_e2e_ecs.js + + export PROJECT_DIRECTORY="$ECS_SRC_DIR" + $AUTH_AWS_DIR/aws_setup.sh ecs run-aws-auth-test-with-aws-web-identity-credentials: - command: shell.exec @@ -955,56 +839,7 @@ functions: echo "This platform does not support the web identity auth test, skipping..." exit 0 fi - cd ${DRIVERS_TOOLS}/.evergreen/auth_aws - . ./activate_venv.sh - mongo aws_e2e_web_identity.js - - command: shell.exec - type: test - params: - shell: "bash" - working_dir: "src" - silent: true - script: | - if [ "${SKIP_WEB_IDENTITY_AUTH_TEST}" = "true" ]; then - echo "This platform does not support the web identity auth test, skipping..." - exit 0 - fi - # DO NOT ECHO WITH XTRACE - cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" - export AWS_ROLE_ARN="${iam_auth_assume_web_role_name}" - export AWS_WEB_IDENTITY_TOKEN_FILE="${iam_web_identity_token_file}" - export MONGODB_URI="mongodb://localhost" - EOF - - command: shell.exec - type: test - params: - shell: "bash" - working_dir: "src" - script: | - ${PREPARE_SHELL} - if [ "${SKIP_WEB_IDENTITY_AUTH_TEST}" = "true" ]; then - echo "This platform does not support the web identity auth test, skipping..." - exit 0 - fi - ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh - - command: shell.exec - type: test - params: - shell: "bash" - working_dir: "src" - silent: true - script: | - if [ "${SKIP_WEB_IDENTITY_AUTH_TEST}" = "true" ]; then - echo "This platform does not support the web identity auth test, skipping..." - exit 0 - fi - # DO NOT ECHO WITH XTRACE - cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" - export AWS_ROLE_ARN="${iam_auth_assume_web_role_name}" - export AWS_WEB_IDENTITY_TOKEN_FILE="${iam_web_identity_token_file}" - export AWS_ROLE_SESSION_NAME="test" - export MONGODB_URI="mongodb://localhost" - EOF + ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh web-identity - command: shell.exec type: test params: @@ -1016,7 +851,8 @@ functions: echo "This platform does not support the web identity auth test, skipping..." exit 0 fi - ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh + export AWS_ROLE_SESSION_NAME="test" + ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-test.sh web-identity start-kms-mock-server: - command: shell.exec diff --git a/.evergreen/run-mongodb-aws-test.sh b/.evergreen/run-mongodb-aws-test.sh index 4652734ff8..3b213b249c 100644 --- a/.evergreen/run-mongodb-aws-test.sh +++ b/.evergreen/run-mongodb-aws-test.sh @@ -12,20 +12,9 @@ set -o errexit # Exit the script with error if any of the commands fail # mechanism. echo "Running MONGODB-AWS authentication tests" -# ensure no secrets are printed in log files -set +x -# load the script -shopt -s expand_aliases # needed for `urlencode` alias -[ -s "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" ] && source "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" - -MONGODB_URI=${MONGODB_URI:-"mongodb://localhost"} -MONGODB_URI="${MONGODB_URI}/aws?authMechanism=MONGODB-AWS" -if [[ -n ${SESSION_TOKEN} ]]; then - MONGODB_URI="${MONGODB_URI}&authMechanismProperties=AWS_SESSION_TOKEN:${SESSION_TOKEN}" -fi - -export MONGODB_URI="$MONGODB_URI" +# Handle credentials and environment setup. +. $DRIVERS_TOOLS/.evergreen/auth_aws/aws_setup.sh $1 # show test output set -x From 3a07cb190cee239b59795758a6f26898cb8cb78d Mon Sep 17 00:00:00 2001 From: Lokesh Kumar Date: Mon, 30 Oct 2023 12:54:39 +0100 Subject: [PATCH 3/4] GODRIVER-2005 - Replace "require" library with "assert" in documentation examples (#1438) --- examples/documentation_examples/examples.go | 445 +++++++++--------- .../documentation_examples/examples_test.go | 4 +- 2 files changed, 224 insertions(+), 225 deletions(-) diff --git a/examples/documentation_examples/examples.go b/examples/documentation_examples/examples.go index b188448a02..ca92646865 100644 --- a/examples/documentation_examples/examples.go +++ b/examples/documentation_examples/examples.go @@ -18,7 +18,7 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/internal/require" + "go.mongodb.org/mongo-driver/internal/assert" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/integration/mtest" "go.mongodb.org/mongo-driver/mongo/options" @@ -33,8 +33,8 @@ func requireCursorLength(t *testing.T, cursor *mongo.Cursor, length int) { i++ } - require.NoError(t, cursor.Err()) - require.Equal(t, i, length) + assert.NoError(t, cursor.Err()) + assert.Equal(t, i, length) } func containsKey(doc bson.Raw, key ...string) bool { @@ -46,7 +46,7 @@ func parseDate(t *testing.T, dateString string) time.Time { rfc3339MilliLayout := "2006-01-02T15:04:05.999Z07:00" // layout defined with Go reference time parsedDate, err := time.Parse(rfc3339MilliLayout, dateString) - require.NoError(t, err) + assert.NoError(t, err) return parsedDate } @@ -56,7 +56,7 @@ func InsertExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("inventory_insert") err := coll.Drop(context.Background()) - require.NoError(t, err) + assert.NoError(t, err) { // Start Example 1 @@ -76,8 +76,8 @@ func InsertExamples(t *testing.T, db *mongo.Database) { // End Example 1 - require.NoError(t, err) - require.NotNil(t, result.InsertedID) + assert.NoError(t, err) + assert.NotNil(t, result.InsertedID) } { @@ -90,9 +90,8 @@ func InsertExamples(t *testing.T, db *mongo.Database) { // End Example 2 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) - } { @@ -135,8 +134,8 @@ func InsertExamples(t *testing.T, db *mongo.Database) { // End Example 3 - require.NoError(t, err) - require.Len(t, result.InsertedIDs, 3) + assert.NoError(t, err) + assert.Len(t, result.InsertedIDs, 3) } } @@ -146,7 +145,7 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("inventory_query_top") err := coll.Drop(context.Background()) - require.NoError(t, err) + assert.NoError(t, err) { // Start Example 6 @@ -208,8 +207,8 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 6 - require.NoError(t, err) - require.Len(t, result.InsertedIDs, 5) + assert.NoError(t, err) + assert.Len(t, result.InsertedIDs, 5) } { @@ -222,7 +221,7 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 7 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 5) } @@ -236,7 +235,7 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 9 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 2) } @@ -249,7 +248,7 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 10 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 5) } @@ -265,7 +264,7 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 11 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -284,7 +283,7 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 12 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 3) } @@ -303,7 +302,7 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 13 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 2) } @@ -315,7 +314,7 @@ func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("inventory_query_embedded") err := coll.Drop(context.Background()) - require.NoError(t, err) + assert.NoError(t, err) { // Start Example 14 @@ -377,8 +376,8 @@ func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 14 - require.NoError(t, err) - require.Len(t, result.InsertedIDs, 5) + assert.NoError(t, err) + assert.Len(t, result.InsertedIDs, 5) } { @@ -396,7 +395,7 @@ func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 15 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -415,7 +414,7 @@ func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 16 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 0) } @@ -429,7 +428,7 @@ func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 17 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 2) } @@ -446,7 +445,7 @@ func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 18 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 4) } @@ -465,7 +464,7 @@ func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 19 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -477,7 +476,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("inventory_query_array") err := coll.Drop(context.Background()) - require.NoError(t, err) + assert.NoError(t, err) { // Start Example 20 @@ -519,8 +518,8 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) { // End Example 20 - require.NoError(t, err) - require.Len(t, result.InsertedIDs, 5) + assert.NoError(t, err) + assert.Len(t, result.InsertedIDs, 5) } { @@ -533,7 +532,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) { // End Example 21 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -548,7 +547,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) { // End Example 22 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 4) } @@ -563,7 +562,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) { // End Example 23 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 4) } @@ -580,7 +579,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) { // End Example 24 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -598,7 +597,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) { // End Example 25 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 4) } @@ -618,7 +617,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) { // End Example 26 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -635,7 +634,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) { // End Example 27 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -652,7 +651,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) { // End Example 28 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -664,7 +663,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("inventory_query_array_embedded") err := coll.Drop(context.Background()) - require.NoError(t, err) + assert.NoError(t, err) { // Start Example 29 @@ -737,8 +736,8 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 29 - require.NoError(t, err) - require.Len(t, result.InsertedIDs, 5) + assert.NoError(t, err) + assert.Len(t, result.InsertedIDs, 5) } { @@ -755,7 +754,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 30 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -773,7 +772,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 31 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 0) } @@ -790,7 +789,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 32 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 3) } @@ -807,7 +806,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 33 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 5) } @@ -827,7 +826,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 34 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -849,7 +848,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 35 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 3) } @@ -867,7 +866,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 36 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 4) } @@ -883,7 +882,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) { // End Example 37 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 2) } } @@ -894,7 +893,7 @@ func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("inventory_query_null_missing") err := coll.Drop(context.Background()) - require.NoError(t, err) + assert.NoError(t, err) { // Start Example 38 @@ -913,8 +912,8 @@ func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 38 - require.NoError(t, err) - require.Len(t, result.InsertedIDs, 2) + assert.NoError(t, err) + assert.Len(t, result.InsertedIDs, 2) } { @@ -928,7 +927,7 @@ func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 39 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 2) } @@ -945,7 +944,7 @@ func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 40 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } @@ -962,7 +961,7 @@ func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) { // End Example 41 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 1) } } @@ -973,7 +972,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("inventory_project") err := coll.Drop(context.Background()) - require.NoError(t, err) + assert.NoError(t, err) { // Start Example 42 @@ -1064,8 +1063,8 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) { // End Example 42 - require.NoError(t, err) - require.Len(t, result.InsertedIDs, 5) + assert.NoError(t, err) + assert.Len(t, result.InsertedIDs, 5) } { @@ -1078,7 +1077,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) { // End Example 43 - require.NoError(t, err) + assert.NoError(t, err) requireCursorLength(t, cursor, 3) } @@ -1100,19 +1099,19 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) { // End Example 44 - require.NoError(t, err) + assert.NoError(t, err) for cursor.Next(context.Background()) { doc := cursor.Current - require.True(t, containsKey(doc, "_id")) - require.True(t, containsKey(doc, "item")) - require.True(t, containsKey(doc, "status")) - require.False(t, containsKey(doc, "size")) - require.False(t, containsKey(doc, "instock")) + assert.True(t, containsKey(doc, "_id")) + assert.True(t, containsKey(doc, "item")) + assert.True(t, containsKey(doc, "status")) + assert.False(t, containsKey(doc, "size")) + assert.False(t, containsKey(doc, "instock")) } - require.NoError(t, cursor.Err()) + assert.NoError(t, cursor.Err()) } { @@ -1134,19 +1133,19 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) { // End Example 45 - require.NoError(t, err) + assert.NoError(t, err) for cursor.Next(context.Background()) { doc := cursor.Current - require.False(t, containsKey(doc, "_id")) - require.True(t, containsKey(doc, "item")) - require.True(t, containsKey(doc, "status")) - require.False(t, containsKey(doc, "size")) - require.False(t, containsKey(doc, "instock")) + assert.False(t, containsKey(doc, "_id")) + assert.True(t, containsKey(doc, "item")) + assert.True(t, containsKey(doc, "status")) + assert.False(t, containsKey(doc, "size")) + assert.False(t, containsKey(doc, "instock")) } - require.NoError(t, cursor.Err()) + assert.NoError(t, cursor.Err()) } { @@ -1167,19 +1166,19 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) { // End Example 46 - require.NoError(t, err) + assert.NoError(t, err) for cursor.Next(context.Background()) { doc := cursor.Current - require.True(t, containsKey(doc, "_id")) - require.True(t, containsKey(doc, "item")) - require.False(t, containsKey(doc, "status")) - require.True(t, containsKey(doc, "size")) - require.False(t, containsKey(doc, "instock")) + assert.True(t, containsKey(doc, "_id")) + assert.True(t, containsKey(doc, "item")) + assert.False(t, containsKey(doc, "status")) + assert.True(t, containsKey(doc, "size")) + assert.False(t, containsKey(doc, "instock")) } - require.NoError(t, cursor.Err()) + assert.NoError(t, cursor.Err()) } { @@ -1201,24 +1200,24 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) { // End Example 47 - require.NoError(t, err) + assert.NoError(t, err) for cursor.Next(context.Background()) { doc := cursor.Current - require.True(t, containsKey(doc, "_id")) - require.True(t, containsKey(doc, "item")) - require.True(t, containsKey(doc, "status")) - require.True(t, containsKey(doc, "size")) - require.False(t, containsKey(doc, "instock")) + assert.True(t, containsKey(doc, "_id")) + assert.True(t, containsKey(doc, "item")) + assert.True(t, containsKey(doc, "status")) + assert.True(t, containsKey(doc, "size")) + assert.False(t, containsKey(doc, "instock")) - require.True(t, containsKey(doc, "size", "uom")) - require.False(t, containsKey(doc, "size", "h")) - require.False(t, containsKey(doc, "size", "w")) + assert.True(t, containsKey(doc, "size", "uom")) + assert.False(t, containsKey(doc, "size", "h")) + assert.False(t, containsKey(doc, "size", "w")) } - require.NoError(t, cursor.Err()) + assert.NoError(t, cursor.Err()) } { @@ -1238,24 +1237,24 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) { // End Example 48 - require.NoError(t, err) + assert.NoError(t, err) for cursor.Next(context.Background()) { doc := cursor.Current - require.True(t, containsKey(doc, "_id")) - require.True(t, containsKey(doc, "item")) - require.True(t, containsKey(doc, "status")) - require.True(t, containsKey(doc, "size")) - require.True(t, containsKey(doc, "instock")) + assert.True(t, containsKey(doc, "_id")) + assert.True(t, containsKey(doc, "item")) + assert.True(t, containsKey(doc, "status")) + assert.True(t, containsKey(doc, "size")) + assert.True(t, containsKey(doc, "instock")) - require.False(t, containsKey(doc, "size", "uom")) - require.True(t, containsKey(doc, "size", "h")) - require.True(t, containsKey(doc, "size", "w")) + assert.False(t, containsKey(doc, "size", "uom")) + assert.True(t, containsKey(doc, "size", "h")) + assert.True(t, containsKey(doc, "size", "w")) } - require.NoError(t, cursor.Err()) + assert.NoError(t, cursor.Err()) } { @@ -1277,36 +1276,36 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) { // End Example 49 - require.NoError(t, err) + assert.NoError(t, err) for cursor.Next(context.Background()) { doc := cursor.Current - require.True(t, containsKey(doc, "_id")) - require.True(t, containsKey(doc, "item")) - require.True(t, containsKey(doc, "status")) - require.False(t, containsKey(doc, "size")) - require.True(t, containsKey(doc, "instock")) + assert.True(t, containsKey(doc, "_id")) + assert.True(t, containsKey(doc, "item")) + assert.True(t, containsKey(doc, "status")) + assert.False(t, containsKey(doc, "size")) + assert.True(t, containsKey(doc, "instock")) instock, err := doc.LookupErr("instock") - require.NoError(t, err) + assert.NoError(t, err) vals, err := instock.Array().Values() - require.NoError(t, err) + assert.NoError(t, err) for _, val := range vals { - require.Equal(t, bson.TypeEmbeddedDocument, val.Type) + assert.Equal(t, bson.TypeEmbeddedDocument, val.Type) subdoc := val.Document() elems, err := subdoc.Elements() - require.NoError(t, err) + assert.NoError(t, err) - require.Equal(t, 1, len(elems)) + assert.Equal(t, 1, len(elems)) _, err = subdoc.LookupErr("qty") - require.NoError(t, err) + assert.NoError(t, err) } } - require.NoError(t, cursor.Err()) + assert.NoError(t, cursor.Err()) } { @@ -1330,25 +1329,25 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) { // End Example 50 - require.NoError(t, err) + assert.NoError(t, err) for cursor.Next(context.Background()) { doc := cursor.Current - require.True(t, containsKey(doc, "_id")) - require.True(t, containsKey(doc, "item")) - require.True(t, containsKey(doc, "status")) - require.False(t, containsKey(doc, "size")) - require.True(t, containsKey(doc, "instock")) + assert.True(t, containsKey(doc, "_id")) + assert.True(t, containsKey(doc, "item")) + assert.True(t, containsKey(doc, "status")) + assert.False(t, containsKey(doc, "size")) + assert.True(t, containsKey(doc, "instock")) instock, err := doc.LookupErr("instock") - require.NoError(t, err) + assert.NoError(t, err) vals, err := instock.Array().Values() - require.NoError(t, err) - require.Equal(t, len(vals), 1) + assert.NoError(t, err) + assert.Equal(t, len(vals), 1) } - require.NoError(t, cursor.Err()) + assert.NoError(t, cursor.Err()) } } @@ -1358,7 +1357,7 @@ func UpdateExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("inventory_update") err := coll.Drop(context.Background()) - require.NoError(t, err) + assert.NoError(t, err) { // Start Example 51 @@ -1470,8 +1469,8 @@ func UpdateExamples(t *testing.T, db *mongo.Database) { // End Example 51 - require.NoError(t, err) - require.Len(t, result.InsertedIDs, 10) + assert.NoError(t, err) + assert.Len(t, result.InsertedIDs, 10) } { @@ -1495,9 +1494,9 @@ func UpdateExamples(t *testing.T, db *mongo.Database) { // End Example 52 - require.NoError(t, err) - require.Equal(t, int64(1), result.MatchedCount) - require.Equal(t, int64(1), result.ModifiedCount) + assert.NoError(t, err) + assert.Equal(t, int64(1), result.MatchedCount) + assert.Equal(t, int64(1), result.ModifiedCount) cursor, err := coll.Find( context.Background(), @@ -1505,23 +1504,23 @@ func UpdateExamples(t *testing.T, db *mongo.Database) { {"item", "paper"}, }) - require.NoError(t, err) + assert.NoError(t, err) for cursor.Next(context.Background()) { doc := cursor.Current uom, err := doc.LookupErr("size", "uom") - require.NoError(t, err) - require.Equal(t, uom.StringValue(), "cm") + assert.NoError(t, err) + assert.Equal(t, uom.StringValue(), "cm") status, err := doc.LookupErr("status") - require.NoError(t, err) - require.Equal(t, status.StringValue(), "P") + assert.NoError(t, err) + assert.Equal(t, status.StringValue(), "P") - require.True(t, containsKey(doc, "lastModified")) + assert.True(t, containsKey(doc, "lastModified")) } - require.NoError(t, cursor.Err()) + assert.NoError(t, cursor.Err()) } { @@ -1547,9 +1546,9 @@ func UpdateExamples(t *testing.T, db *mongo.Database) { // End Example 53 - require.NoError(t, err) - require.Equal(t, int64(3), result.MatchedCount) - require.Equal(t, int64(3), result.ModifiedCount) + assert.NoError(t, err) + assert.Equal(t, int64(3), result.MatchedCount) + assert.Equal(t, int64(3), result.ModifiedCount) cursor, err := coll.Find( context.Background(), @@ -1559,23 +1558,23 @@ func UpdateExamples(t *testing.T, db *mongo.Database) { }}, }) - require.NoError(t, err) + assert.NoError(t, err) for cursor.Next(context.Background()) { doc := cursor.Current uom, err := doc.LookupErr("size", "uom") - require.NoError(t, err) - require.Equal(t, uom.StringValue(), "cm") + assert.NoError(t, err) + assert.Equal(t, uom.StringValue(), "cm") status, err := doc.LookupErr("status") - require.NoError(t, err) - require.Equal(t, status.StringValue(), "P") + assert.NoError(t, err) + assert.Equal(t, status.StringValue(), "P") - require.True(t, containsKey(doc, "lastModified")) + assert.True(t, containsKey(doc, "lastModified")) } - require.NoError(t, cursor.Err()) + assert.NoError(t, cursor.Err()) } { @@ -1603,9 +1602,9 @@ func UpdateExamples(t *testing.T, db *mongo.Database) { // End Example 54 - require.NoError(t, err) - require.Equal(t, int64(1), result.MatchedCount) - require.Equal(t, int64(1), result.ModifiedCount) + assert.NoError(t, err) + assert.Equal(t, int64(1), result.MatchedCount) + assert.Equal(t, int64(1), result.ModifiedCount) cursor, err := coll.Find( context.Background(), @@ -1613,22 +1612,22 @@ func UpdateExamples(t *testing.T, db *mongo.Database) { {"item", "paper"}, }) - require.NoError(t, err) + assert.NoError(t, err) for cursor.Next(context.Background()) { - require.True(t, containsKey(cursor.Current, "_id")) - require.True(t, containsKey(cursor.Current, "item")) - require.True(t, containsKey(cursor.Current, "instock")) + assert.True(t, containsKey(cursor.Current, "_id")) + assert.True(t, containsKey(cursor.Current, "item")) + assert.True(t, containsKey(cursor.Current, "instock")) instock, err := cursor.Current.LookupErr("instock") - require.NoError(t, err) + assert.NoError(t, err) vals, err := instock.Array().Values() - require.NoError(t, err) - require.Equal(t, len(vals), 2) + assert.NoError(t, err) + assert.Equal(t, len(vals), 2) } - require.NoError(t, cursor.Err()) + assert.NoError(t, cursor.Err()) } } @@ -1639,7 +1638,7 @@ func DeleteExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("inventory_delete") err := coll.Drop(context.Background()) - require.NoError(t, err) + assert.NoError(t, err) { // Start Example 55 @@ -1700,8 +1699,8 @@ func DeleteExamples(t *testing.T, db *mongo.Database) { // End Example 55 - require.NoError(t, err) - require.Len(t, result.InsertedIDs, 5) + assert.NoError(t, err) + assert.Len(t, result.InsertedIDs, 5) } { @@ -1716,8 +1715,8 @@ func DeleteExamples(t *testing.T, db *mongo.Database) { // End Example 57 - require.NoError(t, err) - require.Equal(t, int64(2), result.DeletedCount) + assert.NoError(t, err) + assert.Equal(t, int64(2), result.DeletedCount) } { @@ -1732,8 +1731,8 @@ func DeleteExamples(t *testing.T, db *mongo.Database) { // End Example 58 - require.NoError(t, err) - require.Equal(t, int64(1), result.DeletedCount) + assert.NoError(t, err) + assert.Equal(t, int64(1), result.DeletedCount) } @@ -1744,8 +1743,8 @@ func DeleteExamples(t *testing.T, db *mongo.Database) { // End Example 56 - require.NoError(t, err) - require.Equal(t, int64(2), result.DeletedCount) + assert.NoError(t, err) + assert.Equal(t, int64(2), result.DeletedCount) } } @@ -2015,10 +2014,10 @@ func ChangeStreamExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("inventory_changestream") err := coll.Drop(context.Background()) - require.NoError(t, err) + assert.NoError(t, err) _, err = coll.InsertOne(ctx, bson.D{{"x", int32(1)}}) - require.NoError(t, err) + assert.NoError(t, err) var stop int32 @@ -2036,7 +2035,7 @@ func ChangeStreamExamples(t *testing.T, db *mongo.Database) { // Start Changestream Example 1 cs, err := coll.Watch(ctx, mongo.Pipeline{}) - require.NoError(t, err) + assert.NoError(t, err) defer cs.Close(ctx) ok := cs.Next(ctx) @@ -2044,15 +2043,15 @@ func ChangeStreamExamples(t *testing.T, db *mongo.Database) { // End Changestream Example 1 - require.True(t, ok) - require.NoError(t, err) - require.NotEqual(t, len(next), 0) + assert.True(t, ok) + assert.NoError(t, err) + assert.NotEqual(t, len(next), 0) } { // Start Changestream Example 2 cs, err := coll.Watch(ctx, mongo.Pipeline{}, options.ChangeStream().SetFullDocument(options.UpdateLookup)) - require.NoError(t, err) + assert.NoError(t, err) defer cs.Close(ctx) ok := cs.Next(ctx) @@ -2060,24 +2059,24 @@ func ChangeStreamExamples(t *testing.T, db *mongo.Database) { // End Changestream Example 2 - require.True(t, ok) - require.NoError(t, err) - require.NotEqual(t, len(next), 0) + assert.True(t, ok) + assert.NoError(t, err) + assert.NotEqual(t, len(next), 0) } { original, err := coll.Watch(ctx, mongo.Pipeline{}) - require.NoError(t, err) + assert.NoError(t, err) defer original.Close(ctx) ok := original.Next(ctx) - require.True(t, ok) + assert.True(t, ok) // Start Changestream Example 3 resumeToken := original.ResumeToken() cs, err := coll.Watch(ctx, mongo.Pipeline{}, options.ChangeStream().SetResumeAfter(resumeToken)) - require.NoError(t, err) + assert.NoError(t, err) defer cs.Close(ctx) ok = cs.Next(ctx) @@ -2085,9 +2084,9 @@ func ChangeStreamExamples(t *testing.T, db *mongo.Database) { // End Changestream Example 3 - require.True(t, ok) - require.NoError(t, err) - require.NotEqual(t, len(result), 0) + assert.True(t, ok) + assert.NoError(t, err) + assert.NotEqual(t, len(result), 0) } { @@ -2098,7 +2097,7 @@ func ChangeStreamExamples(t *testing.T, db *mongo.Database) { bson.D{{"operationType", "delete"}}}}}, }}} cs, err := coll.Watch(ctx, pipeline) - require.NoError(t, err) + assert.NoError(t, err) defer cs.Close(ctx) ok := cs.Next(ctx) @@ -2106,9 +2105,9 @@ func ChangeStreamExamples(t *testing.T, db *mongo.Database) { // End Changestream Example 4 - require.True(t, ok) - require.NoError(t, err) - require.NotEqual(t, len(next), 0) + assert.True(t, ok) + assert.NoError(t, err) + assert.NotEqual(t, len(next), 0) } atomic.StoreInt32(&stop, 1) @@ -2124,11 +2123,11 @@ func AggregationExamples(t *testing.T, db *mongo.Database) { airAlliancesColl := db.Collection("air_alliances") err := salesColl.Drop(ctx) - require.NoError(t, err) + assert.NoError(t, err) err = airlinesColl.Drop(ctx) - require.NoError(t, err) + assert.NoError(t, err) err = airAlliancesColl.Drop(ctx) - require.NoError(t, err) + assert.NoError(t, err) date20180208 := parseDate(t, "2018-02-08T09:00:00.000Z") date20180109 := parseDate(t, "2018-01-09T07:12:00.000Z") @@ -2365,12 +2364,12 @@ func AggregationExamples(t *testing.T, db *mongo.Database) { airlinesResult, airlinesErr := airlinesColl.InsertMany(ctx, airlines) airAlliancesResult, airAlliancesErr := airAlliancesColl.InsertMany(ctx, airAlliances) - require.NoError(t, salesErr) - require.Len(t, salesResult.InsertedIDs, 6) - require.NoError(t, airlinesErr) - require.Len(t, airlinesResult.InsertedIDs, 7) - require.NoError(t, airAlliancesErr) - require.Len(t, airAlliancesResult.InsertedIDs, 3) + assert.NoError(t, salesErr) + assert.Len(t, salesResult.InsertedIDs, 6) + assert.NoError(t, airlinesErr) + assert.Len(t, airlinesResult.InsertedIDs, 7) + assert.NoError(t, airAlliancesErr) + assert.Len(t, airAlliancesResult.InsertedIDs, 3) { // Start Aggregation Example 1 @@ -2391,7 +2390,7 @@ func AggregationExamples(t *testing.T, db *mongo.Database) { // End Aggregation Example 1 - require.NoError(t, err) + assert.NoError(t, err) defer cursor.Close(ctx) requireCursorLength(t, cursor, 5) } @@ -2436,7 +2435,7 @@ func AggregationExamples(t *testing.T, db *mongo.Database) { // End Aggregation Example 2 - require.NoError(t, err) + assert.NoError(t, err) defer cursor.Close(ctx) requireCursorLength(t, cursor, 4) } @@ -2485,7 +2484,7 @@ func AggregationExamples(t *testing.T, db *mongo.Database) { // End Aggregation Example 3 - require.NoError(t, err) + assert.NoError(t, err) defer cursor.Close(ctx) requireCursorLength(t, cursor, 4) } @@ -2529,7 +2528,7 @@ func AggregationExamples(t *testing.T, db *mongo.Database) { // End Aggregation Example 4 - require.NoError(t, err) + assert.NoError(t, err) defer cursor.Close(ctx) requireCursorLength(t, cursor, 3) } @@ -2632,7 +2631,7 @@ func RunCommandExamples(t *testing.T, db *mongo.Database) { coll := db.Collection("restaurants") err := coll.Drop(ctx) - require.NoError(t, err) + assert.NoError(t, err) { // Start RunCommand Example 1 @@ -2641,7 +2640,7 @@ func RunCommandExamples(t *testing.T, db *mongo.Database) { // End RunCommand Example 1 err := res.Err() - require.NoError(t, err) + assert.NoError(t, err) } } @@ -2654,9 +2653,9 @@ func IndexExamples(t *testing.T, db *mongo.Database) { restaurantsColl := db.Collection("restaurants") err := recordsColl.Drop(ctx) - require.NoError(t, err) + assert.NoError(t, err) err = restaurantsColl.Drop(ctx) - require.NoError(t, err) + assert.NoError(t, err) records := []interface{}{ bson.D{ @@ -2723,10 +2722,10 @@ func IndexExamples(t *testing.T, db *mongo.Database) { recordsResult, recordsErr := recordsColl.InsertMany(ctx, records) restaurantsResult, restaurantsErr := restaurantsColl.InsertMany(ctx, restaurants) - require.NoError(t, recordsErr) - require.Len(t, recordsResult.InsertedIDs, 3) - require.NoError(t, restaurantsErr) - require.Len(t, restaurantsResult.InsertedIDs, 5) + assert.NoError(t, recordsErr) + assert.Len(t, recordsResult.InsertedIDs, 3) + assert.NoError(t, restaurantsErr) + assert.Len(t, restaurantsResult.InsertedIDs, 5) { // Start Index Example 1 @@ -2739,7 +2738,7 @@ func IndexExamples(t *testing.T, db *mongo.Database) { // End Index Example 1 - require.NoError(t, err) + assert.NoError(t, err) } { // Start Index Example 2 @@ -2760,7 +2759,7 @@ func IndexExamples(t *testing.T, db *mongo.Database) { // End Index Example 2 - require.NoError(t, err) + assert.NoError(t, err) } } @@ -2866,7 +2865,7 @@ func StableAPIStrictCountExample(t *testing.T) { clientOpts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPIOptions) client, err := mongo.Connect(context.TODO(), clientOpts) - require.Nil(t, err, "Connect error: %v", err) + assert.Nil(t, err, "Connect error: %v", err) defer func() { _ = client.Disconnect(context.TODO()) }() // Start Versioned API Example 5 @@ -2886,12 +2885,12 @@ func StableAPIStrictCountExample(t *testing.T) { // End Versioned API Example 5 defer func() { _ = coll.Drop(context.TODO()) }() - require.Nil(t, err, "InsertMany error: %v", err) + assert.Nil(t, err, "InsertMany error: %v", err) res := client.Database("db").RunCommand(context.TODO(), bson.D{{"count", "sales"}}) - require.NotNil(t, res.Err(), "expected RunCommand error, got nil") + assert.NotNil(t, res.Err(), "expected RunCommand error, got nil") expectedErr := "Provided apiStrict:true, but the command count is not in API Version 1" - require.True(t, strings.Contains(res.Err().Error(), expectedErr), + assert.True(t, strings.Contains(res.Err().Error(), expectedErr), "expected RunCommand error to contain %q, got %q", expectedErr, res.Err().Error()) // Start Versioned API Example 6 @@ -2905,8 +2904,8 @@ func StableAPIStrictCountExample(t *testing.T) { count, err := coll.CountDocuments(context.TODO(), bson.D{}) // End Versioned API Example 7 - require.Nil(t, err, "CountDocuments error: %v", err) - require.Equal(t, count, int64(8), "expected count to be 8, got %v", count) + assert.Nil(t, err, "CountDocuments error: %v", err) + assert.Equal(t, count, int64(8), "expected count to be 8, got %v", count) // Start Versioned API Example 8 @@ -2940,7 +2939,7 @@ func insertSnapshotQueryTestData(mt *mtest.T) { {"age", 10}, }, }) - require.NoError(mt, err) + assert.NoError(mt, err) dogColl := mt.CreateCollection(mtest.Collection{Name: "dogs"}, true) _, err = dogColl.InsertMany(context.Background(), []interface{}{ @@ -2957,7 +2956,7 @@ func insertSnapshotQueryTestData(mt *mtest.T) { {"age", 2}, }, }) - require.NoError(mt, err) + assert.NoError(mt, err) salesColl := mt.CreateCollection(mtest.Collection{Name: "sales"}, true) _, err = salesColl.InsertMany(context.Background(), []interface{}{ @@ -2967,7 +2966,7 @@ func insertSnapshotQueryTestData(mt *mtest.T) { {"saleDate", time.Now()}, }, }) - require.NoError(mt, err) + assert.NoError(mt, err) } func snapshotQueryPetExample(mt *mtest.T) error { @@ -3030,7 +3029,7 @@ func snapshotQueryPetExample(mt *mtest.T) error { return err } // End Snapshot Query Example 1 - require.Equal(mt, int32(3), adoptablePetsCount, "expected 3 total adoptable pets") + assert.Equal(mt, int32(3), adoptablePetsCount, "expected 3 total adoptable pets") return nil } @@ -3089,7 +3088,7 @@ func snapshotQueryRetailExample(mt *mtest.T) error { return err } // End Snapshot Query Example 2 - require.Equal(mt, int32(1), totalDailySales, "expected 1 total daily sale") + assert.Equal(mt, int32(1), totalDailySales, "expected 1 total daily sale") return nil } @@ -3097,6 +3096,6 @@ func snapshotQueryRetailExample(mt *mtest.T) error { // These appear at https://www.mongodb.com/docs/manual/tutorial/long-running-queries/. func SnapshotQueryExamples(mt *mtest.T) { insertSnapshotQueryTestData(mt) - require.NoError(mt, snapshotQueryPetExample(mt)) - require.NoError(mt, snapshotQueryRetailExample(mt)) + assert.NoError(mt, snapshotQueryPetExample(mt)) + assert.NoError(mt, snapshotQueryRetailExample(mt)) } diff --git a/examples/documentation_examples/examples_test.go b/examples/documentation_examples/examples_test.go index 563146b9dc..141056f6da 100644 --- a/examples/documentation_examples/examples_test.go +++ b/examples/documentation_examples/examples_test.go @@ -15,7 +15,7 @@ import ( "time" "go.mongodb.org/mongo-driver/examples/documentation_examples" - "go.mongodb.org/mongo-driver/internal/require" + "go.mongodb.org/mongo-driver/internal/assert" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/integration/mtest" "go.mongodb.org/mongo-driver/mongo/options" @@ -45,7 +45,7 @@ func TestDocumentationExamples(t *testing.T) { defer cancel() client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(mtest.ClusterURI())) - require.NoError(t, err) + assert.NoError(t, err) defer client.Disconnect(ctx) db := client.Database("documentation_examples") From b8004e68a007b45b68a4cf39a03d98026b2230c9 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 31 Oct 2023 14:51:15 -0500 Subject: [PATCH 4/4] GODRIVER-3018 Use pre-commit for development (#1443) --- .evergreen/ocsp-requirements.txt | 2 +- .evergreen/run-fuzz.sh | 3 +- .evergreen/run-tests.sh | 4 +- .github/workflows/test.yml | 21 ++++++++ .pre-commit-config.yaml | 50 +++++++++++++++++++ README.md | 33 +++++++----- THIRD-PARTY-NOTICES | 6 +-- bson/bsonrw/copier.go | 2 +- bson/mgocompat/bson_test.go | 6 +-- docs/CONTRIBUTING.md | 28 +++++++++-- docs/common-issues.md | 1 + docs/pull_request_template.md | 3 +- etc/api_report.sh | 2 +- etc/assets/docs-mongodb-green.svg | 2 +- etc/assets/godev-bson-blue.svg | 2 +- etc/assets/godev-mongo-blue.svg | 2 +- etc/gen-ec-certs/gen-ec-certs.sh | 3 +- etc/generate_notices.pl | 6 +-- etc/install-libmongocrypt.sh | 2 +- internal/assert/assertion_format.go | 2 +- internal/assert/assertions.go | 4 +- internal/assert/assertions_test.go | 2 +- internal/assert/difflib.go | 2 +- internal/aws/signer/v4/v4_test.go | 2 +- internal/logger/logger.go | 2 +- internal/rand/rand.go | 2 +- internal/require/require.go | 4 +- internal/test/faas/awslambda/Makefile | 1 - internal/test/faas/awslambda/mongodb/main.go | 4 +- mongo/bulk_write.go | 2 +- mongo/collection.go | 2 +- mongo/integration/cursor_test.go | 2 +- .../integration/retryable_reads_prose_test.go | 2 +- .../retryable_writes_prose_test.go | 2 +- mongo/integration/unified/admin_helpers.go | 2 +- .../integration/unified/bulkwrite_helpers.go | 2 +- mongo/integration/unified/entity_test.go | 2 +- mongo/mongo_test.go | 2 +- mongo/options/clientoptions.go | 2 +- mongo/options/clientoptions_test.go | 4 +- .../testdata/one-pk-multiple-certs.pem | 2 +- mongo/results.go | 2 +- testdata/auth/mongodb-aws.rst | 16 +++--- testdata/client-side-encryption/README.rst | 2 +- .../client-side-operations-timeout/README.rst | 2 +- .../README.rst | 6 +-- .../connection-monitoring-and-pooling.rst | 22 ++++---- testdata/crud/README.rst | 2 +- testdata/kmip-certs/README.md | 1 - testdata/mongocrypt/kms-reply.txt | 2 +- testdata/read-write-concern/README.rst | 4 +- testdata/retryable-reads/README.rst | 14 +++--- testdata/retryable-writes/README.rst | 2 +- .../logging/load-balanced.json | 0 .../logging/load-balanced.yml | 0 .../logging/operation-id.json | 0 testdata/transactions/README.rst | 2 +- x/README.md | 4 +- x/bsonx/bsoncore/bsoncore.go | 2 +- x/mongo/driver/DESIGN.md | 4 ++ .../driver/auth/internal/gssapi/gss_wrapper.c | 12 ++--- .../driver/auth/internal/gssapi/gss_wrapper.h | 8 +-- x/mongo/driver/auth/internal/gssapi/sspi.go | 2 +- .../auth/internal/gssapi/sspi_wrapper.c | 6 +-- .../auth/internal/gssapi/sspi_wrapper.h | 4 +- x/mongo/driver/batches.go | 2 +- x/mongo/driver/errors.go | 2 +- x/mongo/driver/ocsp/ocsp.go | 2 +- x/mongo/driver/operation.go | 6 +-- x/mongo/driver/operation/hello.go | 2 +- x/mongo/driver/topology/DESIGN.md | 7 ++- x/mongo/driver/topology/cmap_prose_test.go | 2 +- x/mongo/driver/topology/connection_test.go | 2 +- x/mongo/driver/topology/fsm.go | 4 +- x/mongo/driver/topology/pool_test.go | 2 +- x/mongo/driver/topology/sdam_spec_test.go | 4 +- x/mongo/driver/topology/server.go | 2 +- x/mongo/driver/topology/topology.go | 2 +- x/mongo/driver/topology/topology_options.go | 2 +- 79 files changed, 249 insertions(+), 140 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 .pre-commit-config.yaml mode change 100755 => 100644 etc/gen-ec-certs/gen-ec-certs.sh mode change 100755 => 100644 testdata/server-selection/logging/load-balanced.json mode change 100755 => 100644 testdata/server-selection/logging/load-balanced.yml mode change 100755 => 100644 testdata/server-selection/logging/operation-id.json diff --git a/.evergreen/ocsp-requirements.txt b/.evergreen/ocsp-requirements.txt index 7325f2f8bc..398d15b210 100644 --- a/.evergreen/ocsp-requirements.txt +++ b/.evergreen/ocsp-requirements.txt @@ -1,3 +1,3 @@ asn1crypto==1.3.0 bottle==0.12.20 -oscrypto==1.2.0 \ No newline at end of file +oscrypto==1.2.0 diff --git a/.evergreen/run-fuzz.sh b/.evergreen/run-fuzz.sh index 5871c06c10..3538da7f34 100755 --- a/.evergreen/run-fuzz.sh +++ b/.evergreen/run-fuzz.sh @@ -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 @@ -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 - diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 43b1ac0c29..d4abde9b3b 100644 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -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 @@ -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}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..ab05fafebe --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..c13963a748 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index 82d0a7ba5e..5631fbc5bc 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ The MongoDB supported driver for Go. -------------------------- +______________________________________________________________________ + ## Requirements - Go 1.13 or higher. We aim to support the latest versions of Go. @@ -18,7 +19,8 @@ The MongoDB supported driver for Go. - 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 @@ -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: @@ -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 @@ -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). diff --git a/THIRD-PARTY-NOTICES b/THIRD-PARTY-NOTICES index cd84bb4f0f..9e0bb2ae15 100644 --- a/THIRD-PARTY-NOTICES +++ b/THIRD-PARTY-NOTICES @@ -192,13 +192,13 @@ Copyright (c) 2010-2013 - Gustavo Niemeyer 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 diff --git a/bson/bsonrw/copier.go b/bson/bsonrw/copier.go index c146d02e58..4d279b7fee 100644 --- a/bson/bsonrw/copier.go +++ b/bson/bsonrw/copier.go @@ -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)) diff --git a/bson/mgocompat/bson_test.go b/bson/mgocompat/bson_test.go index 9b4495dcc3..45fb5b27f6 100644 --- a/bson/mgocompat/bson_test.go +++ b/bson/mgocompat/bson_test.go @@ -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) } } }) @@ -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) { diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 8a25e6f4d9..a46749c44b 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -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` @@ -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: @@ -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` @@ -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`. @@ -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: @@ -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. Ensure `docker` is installed and running, and then run: ```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: diff --git a/docs/common-issues.md b/docs/common-issues.md index 0dc3c6ae56..d89ffc323e 100644 --- a/docs/common-issues.md +++ b/docs/common-issues.md @@ -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)). diff --git a/docs/pull_request_template.md b/docs/pull_request_template.md index 2976bfd437..1a3d537d10 100644 --- a/docs/pull_request_template.md +++ b/docs/pull_request_template.md @@ -1,8 +1,9 @@ ## Summary + ## Background & Motivation - + diff --git a/etc/api_report.sh b/etc/api_report.sh index 5478241dca..4c60f76b3f 100755 --- a/etc/api_report.sh +++ b/etc/api_report.sh @@ -8,7 +8,7 @@ if [ "$BASE_SHA" == "$HEAD_SHA" ]; then echo "Skipping API Report" exit 0 fi - + # Ensure a clean checkout. git checkout -b test-api-report git add . diff --git a/etc/assets/docs-mongodb-green.svg b/etc/assets/docs-mongodb-green.svg index ed5d848731..ad7bc74c09 100644 --- a/etc/assets/docs-mongodb-green.svg +++ b/etc/assets/docs-mongodb-green.svg @@ -1 +1 @@ - docsdocsmongodbmongodb \ No newline at end of file + docsdocsmongodbmongodb diff --git a/etc/assets/godev-bson-blue.svg b/etc/assets/godev-bson-blue.svg index 1a4b37b260..055fe77db3 100644 --- a/etc/assets/godev-bson-blue.svg +++ b/etc/assets/godev-bson-blue.svg @@ -1 +1 @@ - go.devgo.devbsonbson \ No newline at end of file + go.devgo.devbsonbson diff --git a/etc/assets/godev-mongo-blue.svg b/etc/assets/godev-mongo-blue.svg index 7b490a3b79..184dd69fb8 100644 --- a/etc/assets/godev-mongo-blue.svg +++ b/etc/assets/godev-mongo-blue.svg @@ -1 +1 @@ - go.devgo.devmongomongo \ No newline at end of file + go.devgo.devmongomongo diff --git a/etc/gen-ec-certs/gen-ec-certs.sh b/etc/gen-ec-certs/gen-ec-certs.sh old mode 100755 new mode 100644 index db901f9d0b..57c03a528f --- a/etc/gen-ec-certs/gen-ec-certs.sh +++ b/etc/gen-ec-certs/gen-ec-certs.sh @@ -1,7 +1,8 @@ +#!/usr/bin/env bash # This script is used to generate Elliptic Curve (EC) certificates. # The EC certificates are used for testing the Go driver with PyKMIP. # PyKMIP does not support Go's default TLS cipher suites with RSA. -# See: GODRIVER-2239. +# See: GODRIVER-2239. set -euo pipefail CA_SERIAL=$RANDOM SERVER_SERIAL=$RANDOM diff --git a/etc/generate_notices.pl b/etc/generate_notices.pl index df375a4577..b40278ef9c 100755 --- a/etc/generate_notices.pl +++ b/etc/generate_notices.pl @@ -228,13 +228,13 @@ sub forked_licenses { 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 diff --git a/etc/install-libmongocrypt.sh b/etc/install-libmongocrypt.sh index af0a266aa9..5c447368ce 100644 --- a/etc/install-libmongocrypt.sh +++ b/etc/install-libmongocrypt.sh @@ -18,7 +18,7 @@ if [ "Windows_NT" = "${OS:-}" ]; then cd .. cp libmongocrypt-all/windows-test/bin/mongocrypt.dll c:/libmongocrypt/bin cp libmongocrypt-all/windows-test/include/mongocrypt/*.h c:/libmongocrypt/include - + rm -rf libmongocrypt-all echo "fetching build for Windows ... end" else diff --git a/internal/assert/assertion_format.go b/internal/assert/assertion_format.go index 5cfaef5519..474a5f42fb 100644 --- a/internal/assert/assertion_format.go +++ b/internal/assert/assertion_format.go @@ -61,7 +61,7 @@ func EqualErrorf(t TestingT, theError error, errString string, msg string, args return EqualError(t, theError, errString, append([]interface{}{msg}, args...)...) } -// EqualValuesf asserts that two objects are equal or convertable to the same types +// EqualValuesf asserts that two objects are equal or convertible to the same types // and equal. // // assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") diff --git a/internal/assert/assertions.go b/internal/assert/assertions.go index b8502b2aa7..c227d47c83 100644 --- a/internal/assert/assertions.go +++ b/internal/assert/assertions.go @@ -172,7 +172,7 @@ func messageFromMsgAndArgs(msgAndArgs ...interface{}) string { // Aligns the provided message so that all lines after the first line start at the same location as the first line. // Assumes that the first line starts at the correct location (after carriage return, tab, label, spacer and tab). -// The longestLabelLen parameter specifies the length of the longest label in the output (required becaues this is the +// The longestLabelLen parameter specifies the length of the longest label in the output (required because this is the // basis on which the alignment occurs). func indentMessageLines(message string, longestLabelLen int) string { outBuf := new(bytes.Buffer) @@ -354,7 +354,7 @@ func truncatingFormat(data interface{}) string { return value } -// EqualValues asserts that two objects are equal or convertable to the same types +// EqualValues asserts that two objects are equal or convertible to the same types // and equal. // // assert.EqualValues(t, uint32(123), int32(123)) diff --git a/internal/assert/assertions_test.go b/internal/assert/assertions_test.go index 2e50a8136f..6c03bbd2e1 100644 --- a/internal/assert/assertions_test.go +++ b/internal/assert/assertions_test.go @@ -691,7 +691,7 @@ func TestError(t *testing.T) { True(t, Error(mockT, err), "Error with error should return True") // go vet check - True(t, Errorf(mockT, err, "example with %s", "formatted message"), "Errorf with error should rturn True") + True(t, Errorf(mockT, err, "example with %s", "formatted message"), "Errorf with error should return True") // returning an empty error interface err = func() error { diff --git a/internal/assert/difflib.go b/internal/assert/difflib.go index cc46ad4474..e13a66a930 100644 --- a/internal/assert/difflib.go +++ b/internal/assert/difflib.go @@ -65,7 +65,7 @@ type OpCode struct { // notion, pairing up elements that appear uniquely in each sequence. // That, and the method here, appear to yield more intuitive difference // reports than does diff. This method appears to be the least vulnerable -// to synching up on blocks of "junk lines", though (like blank lines in +// to syncing up on blocks of "junk lines", though (like blank lines in // ordinary text files, or maybe "

" lines in HTML files). That may be // because this is the only method of the 3 that has a *concept* of // "junk" . diff --git a/internal/aws/signer/v4/v4_test.go b/internal/aws/signer/v4/v4_test.go index a71fe300c7..51966b96db 100644 --- a/internal/aws/signer/v4/v4_test.go +++ b/internal/aws/signer/v4/v4_test.go @@ -305,7 +305,7 @@ func TestSignWithBody_ReplaceRequestBody(t *testing.T) { } if req.Body == origBody { - t.Errorf("expeect request body to not be origBody") + t.Errorf("expect request body to not be origBody") } if req.Body == nil { diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 0762fc8868..03d42814f4 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -19,7 +19,7 @@ import ( // logged for a stringified BSON document. const DefaultMaxDocumentLength = 1000 -// TruncationSuffix are trailling ellipsis "..." appended to a message to +// TruncationSuffix are trailing ellipsis "..." appended to a message to // indicate to the user that truncation occurred. This constant does not count // toward the max document length. const TruncationSuffix = "..." diff --git a/internal/rand/rand.go b/internal/rand/rand.go index ffd0509bd5..4c3d3e6ee2 100644 --- a/internal/rand/rand.go +++ b/internal/rand/rand.go @@ -357,7 +357,7 @@ func (s *LockedSource) Seed(seed uint64) { s.lk.Unlock() } -// seedPos implements Seed for a LockedSource without a race condiiton. +// seedPos implements Seed for a LockedSource without a race condition. func (s *LockedSource) seedPos(seed uint64, readPos *int8) { s.lk.Lock() s.src.Seed(seed) diff --git a/internal/require/require.go b/internal/require/require.go index 901c3818ee..4854bbcd54 100644 --- a/internal/require/require.go +++ b/internal/require/require.go @@ -131,7 +131,7 @@ func EqualErrorf(t TestingT, theError error, errString string, msg string, args t.FailNow() } -// EqualValues asserts that two objects are equal or convertable to the same types +// EqualValues asserts that two objects are equal or convertible to the same types // and equal. // // assert.EqualValues(t, uint32(123), int32(123)) @@ -145,7 +145,7 @@ func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArg t.FailNow() } -// EqualValuesf asserts that two objects are equal or convertable to the same types +// EqualValuesf asserts that two objects are equal or convertible to the same types // and equal. // // assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") diff --git a/internal/test/faas/awslambda/Makefile b/internal/test/faas/awslambda/Makefile index b374dc97b8..82cc7bb955 100644 --- a/internal/test/faas/awslambda/Makefile +++ b/internal/test/faas/awslambda/Makefile @@ -5,4 +5,3 @@ default: # These cases require either building a mongodb docker container or # using a serverless service such as Atlas. sam local invoke --parameter-overrides "MongoDbUri=${MONGODB_URI}" - diff --git a/internal/test/faas/awslambda/mongodb/main.go b/internal/test/faas/awslambda/mongodb/main.go index a0c55f9085..e4aac39688 100644 --- a/internal/test/faas/awslambda/mongodb/main.go +++ b/internal/test/faas/awslambda/mongodb/main.go @@ -25,7 +25,7 @@ const timeout = 60 * time.Second // eventListener supports command, heartbeat, and pool event handlers to record // event durations, as well as the number of heartbeats, commands, and open -// conections. +// connections. type eventListener struct { commandCount int commandDuration int64 @@ -75,7 +75,7 @@ func (listener *eventListener) serverMonitor() *event.ServerMonitor { } // poolMonitor initialize an event.PoolMonitor that will increment each time a -// new conneciton is created and decrement each time a connection is closed. +// new connection is created and decrement each time a connection is closed. func (listener *eventListener) poolMonitor() *event.PoolMonitor { poolEvent := func(e *event.PoolEvent) { switch e.Type { diff --git a/mongo/bulk_write.go b/mongo/bulk_write.go index 58e64f1d9a..42d286ea7d 100644 --- a/mongo/bulk_write.go +++ b/mongo/bulk_write.go @@ -26,7 +26,7 @@ type bulkWriteBatch struct { indexes []int } -// bulkWrite perfoms a bulkwrite operation +// bulkWrite performs a bulkwrite operation type bulkWrite struct { comment interface{} ordered *bool diff --git a/mongo/collection.go b/mongo/collection.go index 6699a6d4c0..fcbfcc77a1 100644 --- a/mongo/collection.go +++ b/mongo/collection.go @@ -1867,7 +1867,7 @@ func (coll *Collection) drop(ctx context.Context) error { ServerAPI(coll.client.serverAPI).Timeout(coll.client.timeout) err = op.Execute(ctx) - // ignore namespace not found erorrs + // ignore namespace not found errors driverErr, ok := err.(driver.Error) if !ok || (ok && !driverErr.NamespaceNotFound()) { return replaceErrors(err) diff --git a/mongo/integration/cursor_test.go b/mongo/integration/cursor_test.go index 9f57d3a6dd..8354bb3325 100644 --- a/mongo/integration/cursor_test.go +++ b/mongo/integration/cursor_test.go @@ -130,7 +130,7 @@ func TestCursor(t *testing.T) { evt := mt.GetStartedEvent() assert.Nil(mt, evt, "expected no events, got %v", evt) - // The batch is exhaused, so the batch length should be 0. Do one Next call, which should do a getMore and + // The batch is exhausted, so the batch length should be 0. Do one Next call, which should do a getMore and // fetch batchSize more documents. The batch length after the call should be (batchSize-1) because Next consumes // one document. assertCursorBatchLength(mt, cursor, 0) diff --git a/mongo/integration/retryable_reads_prose_test.go b/mongo/integration/retryable_reads_prose_test.go index 80f4d3329a..7d153d852f 100644 --- a/mongo/integration/retryable_reads_prose_test.go +++ b/mongo/integration/retryable_reads_prose_test.go @@ -111,7 +111,7 @@ func TestRetryableReadsProse(t *testing.T) { // Note that setting this value greater than 2 will result in false // negatives. The current specification does not account for CSOT, which - // might allow for an "inifinite" number of retries over a period of time. + // might allow for an "infinite" number of retries over a period of time. // Because of this, we only track the "previous server". hostCount int failpointErrorCode int32 diff --git a/mongo/integration/retryable_writes_prose_test.go b/mongo/integration/retryable_writes_prose_test.go index 165c683e36..0c93a45417 100644 --- a/mongo/integration/retryable_writes_prose_test.go +++ b/mongo/integration/retryable_writes_prose_test.go @@ -292,7 +292,7 @@ func TestRetryableWritesProse(t *testing.T) { // Note that setting this value greater than 2 will result in false // negatives. The current specification does not account for CSOT, which - // might allow for an "inifinite" number of retries over a period of time. + // might allow for an "infinite" number of retries over a period of time. // Because of this, we only track the "previous server". hostCount int failpointErrorCode int32 diff --git a/mongo/integration/unified/admin_helpers.go b/mongo/integration/unified/admin_helpers.go index f7bcb99146..29955aed82 100644 --- a/mongo/integration/unified/admin_helpers.go +++ b/mongo/integration/unified/admin_helpers.go @@ -25,7 +25,7 @@ var ( } ) -// terminateOpenSessions executes a killAllSessions command to ensure that sesssions left open on the server by a test +// terminateOpenSessions executes a killAllSessions command to ensure that sessions left open on the server by a test // do not cause future tests to hang. func terminateOpenSessions(ctx context.Context) error { if mtest.CompareServerVersions(mtest.ServerVersion(), "3.6") < 0 { diff --git a/mongo/integration/unified/bulkwrite_helpers.go b/mongo/integration/unified/bulkwrite_helpers.go index 895c57e990..5e5ade0f16 100644 --- a/mongo/integration/unified/bulkwrite_helpers.go +++ b/mongo/integration/unified/bulkwrite_helpers.go @@ -259,7 +259,7 @@ func createBulkWriteModel(rawModel bson.Raw) (mongo.WriteModel, error) { return rom.SetFilter(filter).SetReplacement(replacement), nil default: - return nil, fmt.Errorf("unrecongized request type: %v", requestType) + return nil, fmt.Errorf("unrecognized request type: %v", requestType) } } diff --git a/mongo/integration/unified/entity_test.go b/mongo/integration/unified/entity_test.go index 134e882e2f..3974e58400 100644 --- a/mongo/integration/unified/entity_test.go +++ b/mongo/integration/unified/entity_test.go @@ -73,7 +73,7 @@ func TestEntityMap(t *testing.T) { notFoundErr := newEntityNotFoundError("event list", "bar") assert.Equal(t, err, notFoundErr, "expected error %v, got %v", notFoundErr, err) }) - t.Run("interations entity", func(t *testing.T) { + t.Run("iterations entity", func(t *testing.T) { name := "iters" notFoundName := "bar" notFoundErr := newEntityNotFoundError("iterations", "bar") diff --git a/mongo/mongo_test.go b/mongo/mongo_test.go index fd3f1ce869..8055236a86 100644 --- a/mongo/mongo_test.go +++ b/mongo/mongo_test.go @@ -113,7 +113,7 @@ func TestEnsureID(t *testing.T) { } for _, tc := range testCases { - tc := tc // Capture range varible. + tc := tc // Capture range variable. t.Run(tc.description, func(t *testing.T) { t.Parallel() diff --git a/mongo/options/clientoptions.go b/mongo/options/clientoptions.go index fe9178cc49..6ce514d21c 100644 --- a/mongo/options/clientoptions.go +++ b/mongo/options/clientoptions.go @@ -317,7 +317,7 @@ func (c *ClientOptions) GetURI() string { // ApplyURI parses the given URI and sets options accordingly. The URI can contain host names, IPv4/IPv6 literals, or // an SRV record that will be resolved when the Client is created. When using an SRV record, TLS support is -// implictly enabled. Specify the "tls=false" URI option to override this. +// implicitly enabled. Specify the "tls=false" URI option to override this. // // If the connection string contains any options that have previously been set, it will overwrite them. Options that // correspond to multiple URI parameters, such as WriteConcern, will be completely overwritten if any of the query diff --git a/mongo/options/clientoptions_test.go b/mongo/options/clientoptions_test.go index 7c148ca0bd..4760e05bbb 100644 --- a/mongo/options/clientoptions_test.go +++ b/mongo/options/clientoptions_test.go @@ -623,7 +623,7 @@ func TestClientOptions(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { err := tc.opts.SetDirect(true).Validate() - assert.NotNil(t, err, "expected errror, got nil") + assert.NotNil(t, err, "expected error, got nil") assert.Equal(t, expectedErr.Error(), err.Error(), "expected error %v, got %v", expectedErr, err) }) } @@ -635,7 +635,7 @@ func TestClientOptions(t *testing.T) { opts.cs.Scheme = connstring.SchemeMongoDBSRV err := opts.SetDirect(true).Validate() - assert.NotNil(t, err, "expected errror, got nil") + assert.NotNil(t, err, "expected error, got nil") assert.Equal(t, expectedErr.Error(), err.Error(), "expected error %v, got %v", expectedErr, err) }) }) diff --git a/mongo/options/testdata/one-pk-multiple-certs.pem b/mongo/options/testdata/one-pk-multiple-certs.pem index 7845a6603d..449fc4d314 100644 --- a/mongo/options/testdata/one-pk-multiple-certs.pem +++ b/mongo/options/testdata/one-pk-multiple-certs.pem @@ -75,4 +75,4 @@ KDvyUILEI59TWaScYnQmQcb/v81gLIq1IjaINAkuZcCHAgu2ZWLOSofgnEATiLYH cXyy9WeRpd8nB3pgy1OjCN1E7+K6yHYYJYPQol25znAB5TLPbWwA8ek8fdmC3IpG HOQXMsoPKCdlgNzG1RXalFSIO1AU2nYO5zeVB1l+WbzEp+o/zq0bi/HcvBhNAtRm Lg== ------END CERTIFICATE----- \ No newline at end of file +-----END CERTIFICATE----- diff --git a/mongo/results.go b/mongo/results.go index 8408e8ba1b..2dbaf2af62 100644 --- a/mongo/results.go +++ b/mongo/results.go @@ -87,7 +87,7 @@ func newListDatabasesResultFromOperation(res operation.ListDatabasesResult) List type DatabaseSpecification struct { Name string // The name of the database. SizeOnDisk int64 // The total size of the database files on disk in bytes. - Empty bool // Specfies whether or not the database is empty. + Empty bool // Specifies whether or not the database is empty. } // UpdateResult is the result type returned from UpdateOne, UpdateMany, and ReplaceOne operations. diff --git a/testdata/auth/mongodb-aws.rst b/testdata/auth/mongodb-aws.rst index 1a256b5608..092db3f202 100644 --- a/testdata/auth/mongodb-aws.rst +++ b/testdata/auth/mongodb-aws.rst @@ -12,7 +12,7 @@ There are 5 scenarios drivers MUST test: For brevity, this section gives the values ````, ```` and ```` in place of a valid access key ID, secret access key and session token (also known as a security token). Note that if these values are passed into the URI they MUST be URL encoded. Sample values are below. -.. code-block:: +.. code-block:: AccessKeyId=AKIAI44QH8DHBEXAMPLE SecretAccessKey=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY @@ -25,7 +25,7 @@ Regular credentials Drivers MUST be able to authenticate by providing a valid access key id and secret access key pair as the username and password, respectively, in the MongoDB URI. An example of a valid URI would be: -.. code-block:: +.. code-block:: mongodb://:@localhost/?authMechanism=MONGODB-AWS | @@ -35,10 +35,10 @@ EC2 Credentials Drivers MUST be able to authenticate from an EC2 instance via temporary credentials assigned to the machine. A sample URI on an EC2 machine would be: .. code-block:: - + mongodb://localhost/?authMechanism=MONGODB-AWS | -.. note:: No username, password or session token is passed into the URI. Drivers MUST query the EC2 instance endpoint to obtain these credentials. +.. note:: No username, password or session token is passed into the URI. Drivers MUST query the EC2 instance endpoint to obtain these credentials. ECS instance ============ @@ -49,12 +49,12 @@ Drivers MUST be able to authenticate from an ECS container via temporary credent mongodb://localhost/?authMechanism=MONGODB-AWS | -.. note:: No username, password or session token is passed into the URI. Drivers MUST query the ECS container endpoint to obtain these credentials. +.. note:: No username, password or session token is passed into the URI. Drivers MUST query the ECS container endpoint to obtain these credentials. AssumeRole ========== -Drivers MUST be able to authenticate using temporary credentials returned from an assume role request. These temporary credentials consist of an access key ID, a secret access key, and a security token passed into the URI. A sample URI would be: +Drivers MUST be able to authenticate using temporary credentials returned from an assume role request. These temporary credentials consist of an access key ID, a secret access key, and a security token passed into the URI. A sample URI would be: .. code-block:: @@ -63,12 +63,12 @@ Drivers MUST be able to authenticate using temporary credentials returned from a AWS Lambda ========== -Drivers MUST be able to authenticate via an access key ID, secret access key and optional session token taken from the environment variables, respectively: +Drivers MUST be able to authenticate via an access key ID, secret access key and optional session token taken from the environment variables, respectively: .. code-block:: AWS_ACCESS_KEY_ID - AWS_SECRET_ACCESS_KEY + AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN | diff --git a/testdata/client-side-encryption/README.rst b/testdata/client-side-encryption/README.rst index 137d19b6df..5bbfa246af 100644 --- a/testdata/client-side-encryption/README.rst +++ b/testdata/client-side-encryption/README.rst @@ -1019,7 +1019,7 @@ KMS TLS Tests The following tests that connections to KMS servers with TLS verify peer certificates. The two tests below make use of mock KMS servers which can be run on Evergreen using `the mock KMS server script `_. -Drivers can set up their local Python enviroment for the mock KMS server by running `the virtualenv activation script `_. +Drivers can set up their local Python environment for the mock KMS server by running `the virtualenv activation script `_. To start a mock KMS server on port 8000 with `ca.pem`_ as a CA file and `expired.pem`_ as a cert file, run the following commands from the ``.evergreen/csfle`` directory. diff --git a/testdata/client-side-operations-timeout/README.rst b/testdata/client-side-operations-timeout/README.rst index b3130ef942..1ff923f2e5 100644 --- a/testdata/client-side-operations-timeout/README.rst +++ b/testdata/client-side-operations-timeout/README.rst @@ -371,7 +371,7 @@ This test only applies to drivers that provide an API to abort a GridFS upload s #. Create a new MongoClient (referred to as ``client``) with ``timeoutMS=10``. #. Using ``client``, create a GridFS bucket (referred to as ``bucket``) that wraps the ``db`` database with ``chunkSizeBytes=2``. -#. Call ``bucket.open_upload_stream()`` with the filename ``filename`` to create an upload stream (referred to as ``uploadStream``). +#. Call ``bucket.open_upload_stream()`` with the filename ``filename`` to create an upload stream (referred to as ``uploadStream``). - Expect this to succeed and return a non-null stream. diff --git a/testdata/connection-monitoring-and-pooling/README.rst b/testdata/connection-monitoring-and-pooling/README.rst index 4577255427..016e50507d 100644 --- a/testdata/connection-monitoring-and-pooling/README.rst +++ b/testdata/connection-monitoring-and-pooling/README.rst @@ -67,7 +67,7 @@ All Unit Tests have some of the following fields: - ``address``: The address of the pool emitting the event - ``connectionId``: The id of a connection associated with the event - ``options``: Options used to create the pool - - ``reason``: A reason giving mroe information on why the event was emitted + - ``reason``: A reason giving more information on why the event was emitted - ``ignore``: An array of event names to ignore @@ -143,7 +143,7 @@ The definition of MATCH or MATCHES in the Spec Test Runner is as follows: Pseudocode implementation of ``actual`` MATCHES ``expected``: :: - + If expected is "42" or 42: Assert that actual exists (is not null or undefined) Else: @@ -178,7 +178,7 @@ For each YAML file with ``style: unit``: - Assert that an actual error ``actualError`` was thrown by the main thread - Assert that ``actualError`` MATCHES ``error`` -- Else: +- Else: - Assert that no errors were thrown by the main thread diff --git a/testdata/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst b/testdata/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst index ab99013356..b81b862836 100644 --- a/testdata/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst +++ b/testdata/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst @@ -19,7 +19,7 @@ Abstract Drivers currently support a variety of options that allow users to configure connection pooling behavior. Users are confused by drivers supporting different subsets of these options. Additionally, drivers implement their connection pools differently, making it difficult to design cross-driver pool functionality. By unifying and codifying pooling options and behavior across all drivers, we will increase user comprehension and code base maintainability. -META +META ==== The keywords “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in `RFC 2119 `_. @@ -234,18 +234,18 @@ A driver-defined entity that encapsulates all non-monitoring connections associa * The Queue of threads waiting for a connection to be available */ waitQueue: WaitQueue; - + /** * A generation number representing the SDAM generation of the pool */ generation: number; - + /** * An integer expressing how many total connections * (active + in use) the pool currently has */ totalConnectionCount: number; - + /** * An integer expressing how many connections are currently * available in the pool. @@ -525,12 +525,12 @@ Events * Emitted when a Connection Pool creates a Connection object. * NOTE: This does not mean that the connection is ready for use. */ - interface ConnectionCreatedEvent { + interface ConnectionCreatedEvent { /** * The ServerAddress of the Endpoint the pool is attempting to connect to. */ address: string; - + /** * The ID of the Connection */ @@ -545,7 +545,7 @@ Events * The ServerAddress of the Endpoint the pool is attempting to connect to. */ address: string; - + /** * The ID of the Connection */ @@ -560,12 +560,12 @@ Events * The ServerAddress of the Endpoint the pool is attempting to connect to. */ address: string; - + /** * The ID of the Connection */ connectionId: number; - + /** * A reason explaining why this connection was closed. * Can be implemented as a string or enum. @@ -597,7 +597,7 @@ Events * The ServerAddress of the Endpoint the pool is attempting to connect to. */ address: string; - + /** * A reason explaining why connection check out failed. * Can be implemented as a string or enum. @@ -632,7 +632,7 @@ Events * The ServerAddress of the Endpoint the pool is attempting to connect to. */ address: string; - + /** * The ID of the Connection */ diff --git a/testdata/crud/README.rst b/testdata/crud/README.rst index 2cf319b643..6fd4626c06 100644 --- a/testdata/crud/README.rst +++ b/testdata/crud/README.rst @@ -89,7 +89,7 @@ For each test file: - Using ``globalMongoClient``, check that the current server version satisfies one of the configurations provided in the top-level ``runOn`` field in the test file (if applicable). If the - requirements are not satisifed, the test file should be skipped. + requirements are not satisfied, the test file should be skipped. - Determine the collection and database under test, utilizing the top-level ``collection_name`` and/or ``database_name`` fields if present. diff --git a/testdata/kmip-certs/README.md b/testdata/kmip-certs/README.md index 719eb1f968..383c0228d4 100644 --- a/testdata/kmip-certs/README.md +++ b/testdata/kmip-certs/README.md @@ -1,4 +1,3 @@ These Elliptic Curve (EC) certificates were generated by running `etc/gen-ec-certs/gen-ec-certs.sh`. The EC certificates are used for testing the Go driver with PyKMIP. PyKMIP does not support Golang's default TLS cipher suites with RSA. - diff --git a/testdata/mongocrypt/kms-reply.txt b/testdata/mongocrypt/kms-reply.txt index c2c52e3841..ebbedccc71 100644 --- a/testdata/mongocrypt/kms-reply.txt +++ b/testdata/mongocrypt/kms-reply.txt @@ -3,4 +3,4 @@ x-amzn-RequestId: deeb35e5-4ecb-4bf1-9af5-84a54ff0af0e Content-Type: application/x-amz-json-1.1 Content-Length: 233 -{"KeyId": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0", "Plaintext": "TqhXy3tKckECjy4/ZNykMWG8amBF46isVPzeOgeusKrwheBmYaU8TMG5AHR/NeUDKukqo8hBGgogiQOVpLPkqBQHD8YkLsNbDmHoGOill5QAHnniF/Lz405bGucB5TfR"} \ No newline at end of file +{"KeyId": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0", "Plaintext": "TqhXy3tKckECjy4/ZNykMWG8amBF46isVPzeOgeusKrwheBmYaU8TMG5AHR/NeUDKukqo8hBGgogiQOVpLPkqBQHD8YkLsNbDmHoGOill5QAHnniF/Lz405bGucB5TfR"} diff --git a/testdata/read-write-concern/README.rst b/testdata/read-write-concern/README.rst index 5995590136..df94273510 100644 --- a/testdata/read-write-concern/README.rst +++ b/testdata/read-write-concern/README.rst @@ -3,7 +3,7 @@ Connection String Tests ======================= The YAML and JSON files in this directory tree are platform-independent tests -that drivers can use to prove their conformance to the Read and Write Concern +that drivers can use to prove their conformance to the Read and Write Concern specification. Version @@ -37,7 +37,7 @@ for drivers that might substitute default values *during* parsing. Document ~~~~~~~~ -These tests are designed to ensure compliance with the spec in relation to what should be +These tests are designed to ensure compliance with the spec in relation to what should be sent to the server. Each YAML file contains an object with a single ``tests`` key. This key is an diff --git a/testdata/retryable-reads/README.rst b/testdata/retryable-reads/README.rst index f57adb7d77..0c3a3fee1a 100644 --- a/testdata/retryable-reads/README.rst +++ b/testdata/retryable-reads/README.rst @@ -93,7 +93,7 @@ Each YAML file has the following keys: - ``database_name`` and ``collection_name``: Optional. The database and collection to use for testing. - + - ``bucket_name``: Optional. The GridFS bucket name to use for testing. - ``data``: The data that should exist in the collection(s) under test before @@ -101,19 +101,19 @@ Each YAML file has the following keys: into the collection under test (i.e. ``collection_name``); however, this field may also be an object mapping collection names to arrays of documents to be inserted into the specified collection. - + - ``tests``: An array of tests that are to be run independently of each other. Each test will have some or all of the following fields: - ``description``: The name of the test. - + - ``clientOptions``: Optional, parameters to pass to MongoClient(). - ``useMultipleMongoses`` (optional): If ``true``, the MongoClient for this test should be initialized with multiple mongos seed addresses. If ``false`` or omitted, only a single mongos address should be specified. This field has no effect for non-sharded topologies. - + - ``skipReason``: Optional, string describing why this test should be skipped. - ``failPoint``: Optional, a server fail point to enable, expressed as the @@ -132,10 +132,10 @@ Each YAML file has the following keys: - ``result``: Optional. The return value from the operation, if any. This field may be a scalar (e.g. in the case of a count), a single document, or an array of documents in the case of a multi-document read. - + - ``error``: Optional. If ``true``, the test should expect an error or exception. - + - ``expectations``: Optional list of command-started events. GridFS Tests @@ -159,7 +159,7 @@ data. .. _GridFSBucket spec: https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.rst#configurable-gridfsbucket-class - + Speeding Up Tests ----------------- diff --git a/testdata/retryable-writes/README.rst b/testdata/retryable-writes/README.rst index 2f431ba39d..d681fff285 100644 --- a/testdata/retryable-writes/README.rst +++ b/testdata/retryable-writes/README.rst @@ -317,7 +317,7 @@ and sharded clusters. retryWrites=false to your connection string. and the error code is 20. - + **Note**: Drivers that rely on ``serverStatus`` to determine the storage engine in use MAY skip this test for sharded clusters, since ``mongos`` does not report this information in its ``serverStatus`` response. diff --git a/testdata/server-selection/logging/load-balanced.json b/testdata/server-selection/logging/load-balanced.json old mode 100755 new mode 100644 diff --git a/testdata/server-selection/logging/load-balanced.yml b/testdata/server-selection/logging/load-balanced.yml old mode 100755 new mode 100644 diff --git a/testdata/server-selection/logging/operation-id.json b/testdata/server-selection/logging/operation-id.json old mode 100755 new mode 100644 diff --git a/testdata/transactions/README.rst b/testdata/transactions/README.rst index a1b27dcf01..496a6b2ef8 100644 --- a/testdata/transactions/README.rst +++ b/testdata/transactions/README.rst @@ -255,7 +255,7 @@ Then for each element in ``tests``: - When testing against a sharded cluster and ``useMultipleMongoses`` is ``true`` the client MUST be created with multiple (valid) mongos seed - addreses. + addresses. #. Call ``client.startSession`` twice to create ClientSession objects ``session0`` and ``session1``, using the test's "sessionOptions" if they diff --git a/x/README.md b/x/README.md index ceeabf893d..6d8800a014 100644 --- a/x/README.md +++ b/x/README.md @@ -1,5 +1,5 @@ -MongoDB Go Driver Unstable Libraries -==================================== +# MongoDB Go Driver Unstable Libraries + This directory contains unstable MongoDB Go driver libraries and packages. The APIs of these packages are not stable and there is no backward compatibility guarantee. diff --git a/x/bsonx/bsoncore/bsoncore.go b/x/bsonx/bsoncore/bsoncore.go index e52674aacf..88133293ea 100644 --- a/x/bsonx/bsoncore/bsoncore.go +++ b/x/bsonx/bsoncore/bsoncore.go @@ -235,7 +235,7 @@ func BuildDocumentValue(elems ...[]byte) Value { return Value{Type: bsontype.EmbeddedDocument, Data: BuildDocument(nil, elems...)} } -// BuildDocumentElement will append a BSON embedded document elemnt using key and the provided +// BuildDocumentElement will append a BSON embedded document element using key and the provided // elements and return the extended buffer. func BuildDocumentElement(dst []byte, key string, elems ...[]byte) []byte { return BuildDocument(AppendHeader(dst, bsontype.EmbeddedDocument, key), elems...) diff --git a/x/mongo/driver/DESIGN.md b/x/mongo/driver/DESIGN.md index 2fde89f81f..3c3e6c56cd 100644 --- a/x/mongo/driver/DESIGN.md +++ b/x/mongo/driver/DESIGN.md @@ -1,12 +1,15 @@ # Driver Library Design + This document outlines the design for this package. ## Deployment, Server, and Connection + Acquiring a `Connection` from a `Server` selected from a `Deployment` enables sending and receiving wire messages. A `Deployment` represents an set of MongoDB servers and a `Server` represents a member of that set. These three types form the operation execution stack. ### Compression + Compression is handled by Connection type while uncompression is handled automatically by the Operation type. This is done because the compressor to use for compressing a wire message is chosen by the connection during handshake, while uncompression can be performed without this @@ -14,6 +17,7 @@ information. This does make the design of compression non-symmetric, but it make to implement and more consistent. ## Operation + The `Operation` type handles executing a series of commands using a `Deployment`. For most uses `Operation` will only execute a single command, but the main use case for a series of commands is batch split write commands, such as insert. The type itself is heavily documented, so reading the diff --git a/x/mongo/driver/auth/internal/gssapi/gss_wrapper.c b/x/mongo/driver/auth/internal/gssapi/gss_wrapper.c index ec49d96125..68b7254149 100644 --- a/x/mongo/driver/auth/internal/gssapi/gss_wrapper.c +++ b/x/mongo/driver/auth/internal/gssapi/gss_wrapper.c @@ -12,9 +12,9 @@ #include "gss_wrapper.h" OM_uint32 gssapi_canonicalize_name( - OM_uint32* minor_status, - char *input_name, - gss_OID input_name_type, + OM_uint32* minor_status, + char *input_name, + gss_OID input_name_type, gss_name_t *output_name ) { @@ -39,8 +39,8 @@ OM_uint32 gssapi_canonicalize_name( } int gssapi_error_desc( - OM_uint32 maj_stat, - OM_uint32 min_stat, + OM_uint32 maj_stat, + OM_uint32 min_stat, char **desc ) { @@ -207,7 +207,7 @@ int gssapi_client_wrap_msg( void* input, size_t input_length, void** output, - size_t* output_length + size_t* output_length ) { gss_buffer_desc input_buffer = GSS_C_EMPTY_BUFFER; diff --git a/x/mongo/driver/auth/internal/gssapi/gss_wrapper.h b/x/mongo/driver/auth/internal/gssapi/gss_wrapper.h index 1cb9cd3c18..a105ba58b7 100644 --- a/x/mongo/driver/auth/internal/gssapi/gss_wrapper.h +++ b/x/mongo/driver/auth/internal/gssapi/gss_wrapper.h @@ -32,8 +32,8 @@ typedef struct { } gssapi_client_state; int gssapi_error_desc( - OM_uint32 maj_stat, - OM_uint32 min_stat, + OM_uint32 maj_stat, + OM_uint32 min_stat, char **desc ); @@ -62,11 +62,11 @@ int gssapi_client_wrap_msg( void* input, size_t input_length, void** output, - size_t* output_length + size_t* output_length ); int gssapi_client_destroy( gssapi_client_state *client ); -#endif \ No newline at end of file +#endif diff --git a/x/mongo/driver/auth/internal/gssapi/sspi.go b/x/mongo/driver/auth/internal/gssapi/sspi.go index 36e9633f8f..6e7d3ed8ad 100644 --- a/x/mongo/driver/auth/internal/gssapi/sspi.go +++ b/x/mongo/driver/auth/internal/gssapi/sspi.go @@ -112,7 +112,7 @@ func (sc *SaslClient) Start() (string, []byte, error) { status := C.sspi_client_init(&sc.state, cusername, cpassword) if status != C.SSPI_OK { - return mechName, nil, sc.getError("unable to intitialize client") + return mechName, nil, sc.getError("unable to initialize client") } payload, err := sc.Next(nil) diff --git a/x/mongo/driver/auth/internal/gssapi/sspi_wrapper.c b/x/mongo/driver/auth/internal/gssapi/sspi_wrapper.c index f655654713..bc73723e83 100644 --- a/x/mongo/driver/auth/internal/gssapi/sspi_wrapper.c +++ b/x/mongo/driver/auth/internal/gssapi/sspi_wrapper.c @@ -69,7 +69,7 @@ int sspi_client_init( if (username) { if (password) { SEC_WINNT_AUTH_IDENTITY auth_identity; - + #ifdef _UNICODE auth_identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; #else @@ -186,7 +186,7 @@ int sspi_client_wrap_msg( PVOID input, ULONG input_length, PVOID* output, - ULONG* output_length + ULONG* output_length ) { SecPkgContext_Sizes sizes; @@ -246,4 +246,4 @@ int sspi_client_destroy( sspi_functions->FreeCredentialsHandle(&client->cred); return SSPI_OK; -} \ No newline at end of file +} diff --git a/x/mongo/driver/auth/internal/gssapi/sspi_wrapper.h b/x/mongo/driver/auth/internal/gssapi/sspi_wrapper.h index 2d08e939e5..e59e55c696 100644 --- a/x/mongo/driver/auth/internal/gssapi/sspi_wrapper.h +++ b/x/mongo/driver/auth/internal/gssapi/sspi_wrapper.h @@ -54,11 +54,11 @@ int sspi_client_wrap_msg( PVOID input, ULONG input_length, PVOID* output, - ULONG* output_length + ULONG* output_length ); int sspi_client_destroy( sspi_client_state *client ); -#endif \ No newline at end of file +#endif diff --git a/x/mongo/driver/batches.go b/x/mongo/driver/batches.go index 3e7dca9ac1..be430afa15 100644 --- a/x/mongo/driver/batches.go +++ b/x/mongo/driver/batches.go @@ -17,7 +17,7 @@ import ( var ErrDocumentTooLarge = errors.New("an inserted document is too large") // Batches contains the necessary information to batch split an operation. This is only used for write -// oeprations. +// operations. type Batches struct { Identifier string Documents []bsoncore.Document diff --git a/x/mongo/driver/errors.go b/x/mongo/driver/errors.go index 177aa1234b..3b8b9823b7 100644 --- a/x/mongo/driver/errors.go +++ b/x/mongo/driver/errors.go @@ -40,7 +40,7 @@ var ( TransientTransactionError = "TransientTransactionError" // NetworkError is an error label for network errors. NetworkError = "NetworkError" - // RetryableWriteError is an error lable for retryable write errors. + // RetryableWriteError is an error label for retryable write errors. RetryableWriteError = "RetryableWriteError" // NoWritesPerformed is an error label indicated that no writes were performed for an operation. NoWritesPerformed = "NoWritesPerformed" diff --git a/x/mongo/driver/ocsp/ocsp.go b/x/mongo/driver/ocsp/ocsp.go index 0e7dbfe2d5..849530fde9 100644 --- a/x/mongo/driver/ocsp/ocsp.go +++ b/x/mongo/driver/ocsp/ocsp.go @@ -149,7 +149,7 @@ func processStaple(cfg config, staple []byte) (*ResponseDetails, error) { // If the server has a Must-Staple certificate and the server does not present a stapled OCSP response, error. if mustStaple && len(staple) == 0 { return nil, errors.New("server provided a certificate with the Must-Staple extension but did not " + - "provde a stapled OCSP response") + "provide a stapled OCSP response") } if len(staple) == 0 { diff --git a/x/mongo/driver/operation.go b/x/mongo/driver/operation.go index 6b56191a01..905c9cfc55 100644 --- a/x/mongo/driver/operation.go +++ b/x/mongo/driver/operation.go @@ -846,7 +846,7 @@ func (op Operation) Execute(ctx context.Context) error { // If the error is no longer retryable and has the NoWritesPerformed label, then we should // set the error to the "previous indefinite error" unless the current error is already the - // "previous indefinite error". After reseting, repeat the error check. + // "previous indefinite error". After resetting, repeat the error check. if tt.HasErrorLabel(NoWritesPerformed) && !prevIndefiniteErrIsSet { err = prevIndefiniteErr prevIndefiniteErrIsSet = true @@ -943,7 +943,7 @@ func (op Operation) Execute(ctx context.Context) error { // If the error is no longer retryable and has the NoWritesPerformed label, then we should // set the error to the "previous indefinite error" unless the current error is already the - // "previous indefinite error". After reseting, repeat the error check. + // "previous indefinite error". After resetting, repeat the error check. if tt.HasErrorLabel(NoWritesPerformed) && !prevIndefiniteErrIsSet { err = prevIndefiniteErr prevIndefiniteErrIsSet = true @@ -1873,7 +1873,7 @@ func (op Operation) decodeResult(opcode wiremessage.OpCode, wm []byte) (bsoncore return nil, errors.New("malformed wire message: insufficient bytes to read document sequence") } default: - return nil, fmt.Errorf("malformed wire message: uknown section type %v", stype) + return nil, fmt.Errorf("malformed wire message: unknown section type %v", stype) } } diff --git a/x/mongo/driver/operation/hello.go b/x/mongo/driver/operation/hello.go index de7e05cb5f..35e1b29efd 100644 --- a/x/mongo/driver/operation/hello.go +++ b/x/mongo/driver/operation/hello.go @@ -484,7 +484,7 @@ retry: } if len(dst) > maxLen { - // Implementors SHOULD cumulatively update fields in the + // Implementers SHOULD cumulatively update fields in the // following order until the document is under the size limit // // 1. Omit fields from ``env`` except ``env.name`` diff --git a/x/mongo/driver/topology/DESIGN.md b/x/mongo/driver/topology/DESIGN.md index 6594a85d08..8a67dd9935 100644 --- a/x/mongo/driver/topology/DESIGN.md +++ b/x/mongo/driver/topology/DESIGN.md @@ -1,7 +1,9 @@ # Topology Package Design + This document outlines the design for this package. ## Topology + The `Topology` type handles monitoring the state of a MongoDB deployment and selecting servers. Updating the description is handled by finite state machine which implements the server discovery and monitoring specification. A `Topology` can be connected and fully disconnected, which enables @@ -9,9 +11,11 @@ saving resources. The `Topology` type also handles server selection following th specification. ## Server + The `Server` type handles heartbeating a MongoDB server and holds a pool of connections. ## Connection + Connections are handled by two main types and an auxiliary type. The two main types are `connection` and `Connection`. The first holds most of the logic required to actually read and write wire messages. Instances can be created with the `newConnection` method. Inside the `newConnection` @@ -26,6 +30,7 @@ The connection implementations in this package are conduits for wire messages bu ability to encode, decode, or validate wire messages. That must be handled by consumers. ## Pool + The `pool` type implements a connection pool. It handles caching idle connections and dialing new ones, but it does not track a maximum number of connections. That is the responsibility of a wrapping type, like `Server`. @@ -37,4 +42,4 @@ There is a `close` method, but this is used to close a connection. There are three methods related to getting and putting connections: `get`, `close`, and `put`. The `get` method will either retrieve a connection from the cache or it will dial a new `connection`. The `close` method will close the underlying socket of a `connection`. The `put` method will put a -connection into the pool, placing it in the cahce if there is space, otherwise it will close it. +connection into the pool, placing it in the cache if there is space, otherwise it will close it. diff --git a/x/mongo/driver/topology/cmap_prose_test.go b/x/mongo/driver/topology/cmap_prose_test.go index 53c6e9ba36..9c83b7a9c5 100644 --- a/x/mongo/driver/topology/cmap_prose_test.go +++ b/x/mongo/driver/topology/cmap_prose_test.go @@ -241,7 +241,7 @@ func TestCMAPProse(t *testing.T) { conns = conns[2:] assertConnectionCounts(t, pool, numConns, 0) - // Close and assert that events are published for all conections. + // Close and assert that events are published for all connections. pool.close(context.Background()) assertConnectionCounts(t, pool, numConns, numConns) diff --git a/x/mongo/driver/topology/connection_test.go b/x/mongo/driver/topology/connection_test.go index ab2496b1ac..42c50e65ab 100644 --- a/x/mongo/driver/topology/connection_test.go +++ b/x/mongo/driver/topology/connection_test.go @@ -146,7 +146,7 @@ func TestConnection(t *testing.T) { _ = conn.connect(context.Background()) }() - // Simulate cancelling connection establishment and assert that this cleares the CancelFunc. + // Simulate cancelling connection establishment and assert that this clears the CancelFunc. conn.closeConnectContext() assert.Nil(t, conn.cancelConnectContext, "cancellation function was not cleared") close(doneChan) diff --git a/x/mongo/driver/topology/fsm.go b/x/mongo/driver/topology/fsm.go index 1494ae7807..2acf527b9d 100644 --- a/x/mongo/driver/topology/fsm.go +++ b/x/mongo/driver/topology/fsm.go @@ -48,7 +48,7 @@ func newFSM() *fsm { // where a "nil" value is considered less than 0. // // Otherwise, if the FSM's logicalSessionTimeoutMinutes exist, then this -// function returns the FSM timout. +// function returns the FSM timeout. // // In the case where the FSM timeout DNE, we check all servers to see if any // still do not have a timeout. This function chooses the lowest of the existing @@ -283,7 +283,7 @@ func hasStalePrimary(fsm fsm, srv description.Server) bool { compRes := bytes.Compare(srv.ElectionID[:], fsm.maxElectionID[:]) if wireVersion := srv.WireVersion; wireVersion != nil && wireVersion.Max >= 17 { - // In the Post-6.0 case, a primary is considered "stale" if the server's election ID is greather than the + // In the Post-6.0 case, a primary is considered "stale" if the server's election ID is greater than the // topology's max election ID. In these versions, the primary is also considered "stale" if the server's // election ID is LTE to the topologies election ID and the server's "setVersion" is less than the topology's // max "setVersion". diff --git a/x/mongo/driver/topology/pool_test.go b/x/mongo/driver/topology/pool_test.go index 8a7603dcc4..013403981d 100644 --- a/x/mongo/driver/topology/pool_test.go +++ b/x/mongo/driver/topology/pool_test.go @@ -751,7 +751,7 @@ func TestPool(t *testing.T) { err.(WaitQueueTimeoutError).Wrapped, "expected wrapped error to be a context.DeadlineExceeded") - // Start a goroutine that closes one of the checked-out conections and checks it in. + // Start a goroutine that closes one of the checked-out connections and checks it in. // Expect that the checked-in connection is closed and allows blocked checkOut() to // complete. Assert that the time between checking in the closed connection and when the // checkOut() completes is within 100ms. diff --git a/x/mongo/driver/topology/sdam_spec_test.go b/x/mongo/driver/topology/sdam_spec_test.go index 3548d69b3e..e09ffb87f0 100644 --- a/x/mongo/driver/topology/sdam_spec_test.go +++ b/x/mongo/driver/topology/sdam_spec_test.go @@ -486,11 +486,11 @@ func runTest(t *testing.T, directory string, filename string) { publishedEvents = nil if phase.Outcome.Compatible == nil || *phase.Outcome.Compatible { assert.True(t, topo.fsm.compatible.Load().(bool), "Expected servers to be compatible") - assert.Nil(t, topo.fsm.compatibilityErr, "expected fsm.compatiblity to be nil, got %v", + assert.Nil(t, topo.fsm.compatibilityErr, "expected fsm.compatibility to be nil, got %v", topo.fsm.compatibilityErr) } else { assert.False(t, topo.fsm.compatible.Load().(bool), "Expected servers to not be compatible") - assert.NotNil(t, topo.fsm.compatibilityErr, "expected fsm.compatiblity error to be non-nil") + assert.NotNil(t, topo.fsm.compatibilityErr, "expected fsm.compatibility error to be non-nil") continue } desc := topo.Description() diff --git a/x/mongo/driver/topology/server.go b/x/mongo/driver/topology/server.go index 4a59643282..9ff6e533c4 100644 --- a/x/mongo/driver/topology/server.go +++ b/x/mongo/driver/topology/server.go @@ -429,7 +429,7 @@ func (s *Server) ProcessError(err error, conn driver.Connection) driver.ProcessE } // Ignore errors from stale connections because the error came from a previous generation of the - // connection pool. The root cause of the error has aleady been handled, which is what caused + // connection pool. The root cause of the error has already been handled, which is what caused // the pool generation to increment. Processing errors for stale connections could result in // handling the same error root cause multiple times (e.g. a temporary network interrupt causing // all connections to the same server to return errors). diff --git a/x/mongo/driver/topology/topology.go b/x/mongo/driver/topology/topology.go index b79efed4ed..bbffbd1da7 100644 --- a/x/mongo/driver/topology/topology.go +++ b/x/mongo/driver/topology/topology.go @@ -98,7 +98,7 @@ type Topology struct { subscriptionsClosed bool subLock sync.Mutex - // We should redesign how we Connect and handle individal servers. This is + // We should redesign how we Connect and handle individual servers. This is // too difficult to maintain and it's rather easy to accidentally access // the servers without acquiring the lock or checking if the servers are // closed. This lock should also be an RWMutex. diff --git a/x/mongo/driver/topology/topology_options.go b/x/mongo/driver/topology/topology_options.go index 8deb614815..ec30487187 100644 --- a/x/mongo/driver/topology/topology_options.go +++ b/x/mongo/driver/topology/topology_options.go @@ -72,7 +72,7 @@ func newLogger(opts *options.LoggerOptions) (*logger.Logger, error) { } // NewConfig will translate data from client options into a topology config for building non-default deployments. -// Server and topoplogy options are not honored if a custom deployment is used. +// Server and topology options are not honored if a custom deployment is used. func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, error) { var serverAPI *driver.ServerAPIOptions