Skip to content

Commit 0e47c32

Browse files
GODRIVER-3569 Convert testaws to go test
1 parent f8e4368 commit 0e47c32

File tree

5 files changed

+37
-45
lines changed

5 files changed

+37
-45
lines changed

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/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/testaws/main.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

internal/test/aws/aws_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"errors"
6+
"os"
7+
"testing"
8+
9+
"go.mongodb.org/mongo-driver/v2/bson"
10+
"go.mongodb.org/mongo-driver/v2/internal/require"
11+
"go.mongodb.org/mongo-driver/v2/mongo"
12+
"go.mongodb.org/mongo-driver/v2/mongo/options"
13+
)
14+
15+
func TestAWS(t *testing.T) {
16+
uri := os.Getenv("MONGODB_URI")
17+
18+
client, err := mongo.Connect(options.Client().ApplyURI(uri))
19+
require.NoError(t, err, "Connect error")
20+
21+
defer func() {
22+
err = client.Disconnect(context.Background())
23+
require.NoError(t, err)
24+
}()
25+
26+
coll := client.Database("aws").Collection("test")
27+
28+
err = coll.FindOne(context.Background(), bson.D{{Key: "x", Value: 1}}).Err()
29+
if err != nil && !errors.Is(err, mongo.ErrNoDocuments) {
30+
t.Logf("FindOne error: %v", err)
31+
}
32+
}

0 commit comments

Comments
 (0)