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/test/aws/aws_test.go similarity index 52% rename from internal/cmd/testaws/main.go rename to internal/test/aws/aws_test.go index 0b037bd09c..947ad07e16 100644 --- a/internal/cmd/testaws/main.go +++ b/internal/test/aws/aws_test.go @@ -1,4 +1,4 @@ -// Copyright (C) MongoDB, Inc. 2017-present. +// 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 @@ -9,32 +9,30 @@ package main import ( "context" "errors" - "fmt" "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 main() { +func TestAWS(t *testing.T) { 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)) - } + require.NoError(t, err, "Connect error") defer func() { - if err = client.Disconnect(ctx); err != nil { - panic(fmt.Sprintf("Disconnect error: %v", err)) - } + err = client.Disconnect(context.Background()) + require.NoError(t, 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)) + 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) } }