Skip to content

Commit 0485aea

Browse files
GODRIVER-3569 Convert testaws to go test (#2091)
1 parent 8715790 commit 0485aea

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
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)
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)