From 0e47c326d83b146618f2b33678945da9ea1655e2 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Fri, 6 Jun 2025 15:08:14 -0600 Subject: [PATCH 1/2] GODRIVER-3569 Convert testaws to go test --- Taskfile.yml | 2 +- etc/run-mongodb-aws-ecs-test.sh | 6 ++--- etc/run-mongodb-aws-test.sh | 2 +- internal/cmd/testaws/main.go | 40 --------------------------------- internal/test/aws/aws_test.go | 32 ++++++++++++++++++++++++++ 5 files changed, 37 insertions(+), 45 deletions(-) delete mode 100644 internal/cmd/testaws/main.go create mode 100644 internal/test/aws/aws_test.go diff --git a/Taskfile.yml b/Taskfile.yml index ab552205f5..3473cb4981 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -34,7 +34,7 @@ tasks: build-compile-check-all: bash etc/run-compile-check-test.sh - build-aws-ecs-test: go build ${BUILD_TAGS} ./internal/cmd/testaws/main.go + build-aws-ecs-test: go test -c ./internal/test/aws -o aws.testbin cross-compile: - GOOS=linux GOARCH=386 go build ./... diff --git a/etc/run-mongodb-aws-ecs-test.sh b/etc/run-mongodb-aws-ecs-test.sh index 4e4b794da9..d5aa2f9598 100755 --- a/etc/run-mongodb-aws-ecs-test.sh +++ b/etc/run-mongodb-aws-ecs-test.sh @@ -2,8 +2,8 @@ set -eu if [ "${SKIP_ECS_AUTH_TEST:-}" = "true" ]; then - echo "This platform does not support the ECS auth test, skipping..." - exit 0 + echo "This platform does not support the ECS auth test, skipping..." + exit 0 fi task build-aws-ecs-test @@ -13,7 +13,7 @@ ECS_SRC_DIR=$AUTH_AWS_DIR/src # pack up project directory to ssh it to the container mkdir -p $ECS_SRC_DIR/.evergreen -cp ${PROJECT_DIRECTORY}/main $ECS_SRC_DIR +cp ${PROJECT_DIRECTORY}/aws.testbin $ECS_SRC_DIR/main cp ${PROJECT_DIRECTORY}/.evergreen/run-mongodb-aws-ecs-test.sh $ECS_SRC_DIR/.evergreen tar -czf $ECS_SRC_DIR/src.tgz -C ${PROJECT_DIRECTORY} . diff --git a/etc/run-mongodb-aws-test.sh b/etc/run-mongodb-aws-test.sh index 6438b5810b..ceca8b9c01 100755 --- a/etc/run-mongodb-aws-test.sh +++ b/etc/run-mongodb-aws-test.sh @@ -31,4 +31,4 @@ set -x # For Go 1.16+, Go builds requires a go.mod file in the current working directory or a parent # directory. Spawn a new subshell, "cd" to the project directory, then run "go run". -(cd ${PROJECT_DIRECTORY} && go run "./internal/cmd/testaws/main.go" | tee test.suite) +(cd ${PROJECT_DIRECTORY} && go test -timeout 30m -v ./internal/test/aws/... | tee -a test.suite) diff --git a/internal/cmd/testaws/main.go b/internal/cmd/testaws/main.go deleted file mode 100644 index 0b037bd09c..0000000000 --- a/internal/cmd/testaws/main.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) MongoDB, Inc. 2017-present. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. You may obtain -// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - -package main - -import ( - "context" - "errors" - "fmt" - "os" - - "go.mongodb.org/mongo-driver/v2/bson" - "go.mongodb.org/mongo-driver/v2/mongo" - "go.mongodb.org/mongo-driver/v2/mongo/options" -) - -func main() { - uri := os.Getenv("MONGODB_URI") - ctx := context.Background() - - client, err := mongo.Connect(options.Client().ApplyURI(uri)) - if err != nil { - panic(fmt.Sprintf("Connect error: %v", err)) - } - - defer func() { - if err = client.Disconnect(ctx); err != nil { - panic(fmt.Sprintf("Disconnect error: %v", err)) - } - }() - - db := client.Database("aws") - coll := db.Collection("test") - if err = coll.FindOne(ctx, bson.D{{"x", 1}}).Err(); err != nil && !errors.Is(err, mongo.ErrNoDocuments) { - panic(fmt.Sprintf("FindOne error: %v", err)) - } -} diff --git a/internal/test/aws/aws_test.go b/internal/test/aws/aws_test.go new file mode 100644 index 0000000000..fe2e1fcbd9 --- /dev/null +++ b/internal/test/aws/aws_test.go @@ -0,0 +1,32 @@ +package main + +import ( + "context" + "errors" + "os" + "testing" + + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/internal/require" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" +) + +func TestAWS(t *testing.T) { + uri := os.Getenv("MONGODB_URI") + + client, err := mongo.Connect(options.Client().ApplyURI(uri)) + require.NoError(t, err, "Connect error") + + defer func() { + err = client.Disconnect(context.Background()) + require.NoError(t, err) + }() + + coll := client.Database("aws").Collection("test") + + err = coll.FindOne(context.Background(), bson.D{{Key: "x", Value: 1}}).Err() + if err != nil && !errors.Is(err, mongo.ErrNoDocuments) { + t.Logf("FindOne error: %v", err) + } +} From ac6edfeef9f18d06170ab154f29dfbd4ef01bf43 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Fri, 6 Jun 2025 15:15:58 -0600 Subject: [PATCH 2/2] GODRIVER-3569 Add licenses --- internal/test/aws/aws_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/test/aws/aws_test.go b/internal/test/aws/aws_test.go index fe2e1fcbd9..947ad07e16 100644 --- a/internal/test/aws/aws_test.go +++ b/internal/test/aws/aws_test.go @@ -1,3 +1,9 @@ +// Copyright (C) MongoDB, Inc. 2025-present. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + package main import (