Skip to content

Commit 8d6fc8e

Browse files
Merge branch 'GODRIVER-3419' of github.com:prestonvasquez/mongo-go-driver into GODRIVER-3419
2 parents 36f1aff + b5e51ad commit 8d6fc8e

File tree

9 files changed

+48
-40
lines changed

9 files changed

+48
-40
lines changed

.evergreen/config.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ functions:
213213
type: test
214214
params:
215215
binary: bash
216+
add_expansions_to_env: true
216217
env:
217218
BASE_SHA: "${revision}"
218219
HEAD_SHA: "${github_commit}"
@@ -223,6 +224,7 @@ functions:
223224
type: test
224225
params:
225226
binary: bash
227+
add_expansions_to_env: true
226228
env:
227229
COMMIT: "${github_commit}"
228230
PR_TASK: apply-labels
@@ -233,6 +235,7 @@ functions:
233235
type: test
234236
params:
235237
binary: bash
238+
add_expansions_to_env: true
236239
env:
237240
COMMIT: "${github_commit}"
238241
PR_TASK: assign-reviewer
@@ -647,6 +650,7 @@ tasks:
647650
- name: pull-request-helpers
648651
allowed_requesters: ["patch", "github_pr"]
649652
commands:
653+
- func: assume-test-secrets-ec2-role
650654
- func: "add PR reviewer"
651655
- func: "add PR labels"
652656
- func: "create-api-report"
@@ -1679,11 +1683,11 @@ tasks:
16791683
type: test
16801684
params:
16811685
binary: bash
1686+
add_expansions_to_env: true
16821687
env:
16831688
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/internal/cmd/faas/awslambda
16841689
LAMBDA_STACK_NAME: dbx-go-lambda
16851690
AWS_REGION: us-east-1
1686-
include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
16871691
args: [*task-runner, evg-test-deployed-lambda-aws]
16881692

16891693
- name: "oidc-auth-test"
@@ -2063,6 +2067,7 @@ task_groups:
20632067
params:
20642068
working_dir: src/go.mongodb.org/mongo-driver
20652069
binary: bash
2070+
add_expansions_to_env: true
20662071
env:
20672072
LAMBDA_STACK_NAME: dbx-go-lambda
20682073
AWS_REGION: us-east-1

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ repos:
6565
require_serial: true
6666
pass_filenames: false
6767
entry: etc/golangci-lint.sh
68+
69+
- id: check-licenses
70+
name: check-licenses
71+
language: system
72+
types: [go]
73+
entry: etc/check_license.sh

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ tasks:
3434

3535
build-compile-check-all: bash etc/run-compile-check-test.sh
3636

37-
build-aws-ecs-test: go build ${BUILD_TAGS} ./internal/cmd/testaws/main.go
37+
build-aws-ecs-test: go test -c ./internal/test/aws -o aws.testbin
3838

3939
cross-compile:
4040
- GOOS=linux GOARCH=386 go build ./...

etc/check_license.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ copyright=$"// Copyright (C) MongoDB, Inc. $year-present.
88
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
99
"
1010

11-
add_copyright() {
11+
check_or_add_copyright() {
1212
file=$1
1313

1414
# Check if first 24 bytes match first 24 bytes of copyright notice.
@@ -54,10 +54,23 @@ do
5454
esac
5555
done
5656

57-
# Find all .go files and try to write a license notice.
58-
GO_FILES=$(find . -type f -name "*.go" -print)
57+
# Shift script arguments so $1 contains only optional filename args.
58+
# E.g. check_license.sh -a ./mongo/cursor.go
59+
shift "$((OPTIND - 1))"
60+
FILES=$1
5961

60-
for file in $GO_FILES
62+
# If no filenames were passed, find all .go files and try to write a license
63+
# notice.
64+
if [ -z "$FILES" ]; then
65+
FILES=$(find . -type f -name "*.go" -print)
66+
fi
67+
68+
for file in $FILES
6169
do
62-
add_copyright "$file"
70+
# Skip any files that aren't .go files.
71+
if [[ ! "$file" =~ .go$ ]]; then
72+
continue
73+
fi
74+
75+
check_or_add_copyright "$file"
6376
done

etc/run-mongodb-aws-ecs-test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
set -eu
33

44
if [ "${SKIP_ECS_AUTH_TEST:-}" = "true" ]; then
5-
echo "This platform does not support the ECS auth test, skipping..."
6-
exit 0
5+
echo "This platform does not support the ECS auth test, skipping..."
6+
exit 0
77
fi
88

99
task build-aws-ecs-test
@@ -13,7 +13,7 @@ ECS_SRC_DIR=$AUTH_AWS_DIR/src
1313

1414
# pack up project directory to ssh it to the container
1515
mkdir -p $ECS_SRC_DIR/.evergreen
16-
cp ${PROJECT_DIRECTORY}/main $ECS_SRC_DIR
16+
cp ${PROJECT_DIRECTORY}/aws.testbin $ECS_SRC_DIR/main
1717
cp ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-ecs-test.sh $ECS_SRC_DIR/.evergreen
1818
tar -czf $ECS_SRC_DIR/src.tgz -C ${PROJECT_DIRECTORY} .
1919

etc/run-mongodb-aws-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ set -x
3131

3232
# For Go 1.16+, Go builds requires a go.mod file in the current working directory or a parent
3333
# directory. Spawn a new subshell, "cd" to the project directory, then run "go run".
34-
(cd ${PROJECT_DIRECTORY} && go run "./internal/cmd/testaws/main.go" | tee test.suite)
34+
(cd ${PROJECT_DIRECTORY} && go test -timeout 30m -v ./internal/test/aws/... | tee -a test.suite)

internal/cmd/faas/awslambda/template.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,6 @@ Resources:
3232
Variables:
3333
MONGODB_URI: !Ref MongoDbUri
3434

35-
ApplicationResourceGroup:
36-
Type: AWS::ResourceGroups::Group
37-
Properties:
38-
Name:
39-
Fn::Sub: ApplicationInsights-SAM-${AWS::StackName}
40-
ResourceQuery:
41-
Type: CLOUDFORMATION_STACK_1_0
42-
ApplicationInsightsMonitoring:
43-
Type: AWS::ApplicationInsights::Application
44-
Properties:
45-
ResourceGroupName:
46-
Ref: ApplicationResourceGroup
47-
AutoConfigurationEnabled: 'true'
48-
4935
Outputs:
5036
MongoDBApi:
5137
Description: "API Gateway endpoint URL for Prod stage for MongoDB function"
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) MongoDB, Inc. 2017-present.
1+
// Copyright (C) MongoDB, Inc. 2025-present.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License"); you may
44
// not use this file except in compliance with the License. You may obtain
@@ -9,32 +9,30 @@ package main
99
import (
1010
"context"
1111
"errors"
12-
"fmt"
1312
"os"
13+
"testing"
1414

1515
"go.mongodb.org/mongo-driver/v2/bson"
16+
"go.mongodb.org/mongo-driver/v2/internal/require"
1617
"go.mongodb.org/mongo-driver/v2/mongo"
1718
"go.mongodb.org/mongo-driver/v2/mongo/options"
1819
)
1920

20-
func main() {
21+
func TestAWS(t *testing.T) {
2122
uri := os.Getenv("MONGODB_URI")
22-
ctx := context.Background()
2323

2424
client, err := mongo.Connect(options.Client().ApplyURI(uri))
25-
if err != nil {
26-
panic(fmt.Sprintf("Connect error: %v", err))
27-
}
25+
require.NoError(t, err, "Connect error")
2826

2927
defer func() {
30-
if err = client.Disconnect(ctx); err != nil {
31-
panic(fmt.Sprintf("Disconnect error: %v", err))
32-
}
28+
err = client.Disconnect(context.Background())
29+
require.NoError(t, err)
3330
}()
3431

35-
db := client.Database("aws")
36-
coll := db.Collection("test")
37-
if err = coll.FindOne(ctx, bson.D{{"x", 1}}).Err(); err != nil && !errors.Is(err, mongo.ErrNoDocuments) {
38-
panic(fmt.Sprintf("FindOne error: %v", err))
32+
coll := client.Database("aws").Collection("test")
33+
34+
err = coll.FindOne(context.Background(), bson.D{{Key: "x", Value: 1}}).Err()
35+
if err != nil && !errors.Is(err, mongo.ErrNoDocuments) {
36+
t.Logf("FindOne error: %v", err)
3937
}
4038
}

0 commit comments

Comments
 (0)