From 033c29ccbe2cf9b44db3e7bbb251b9bc2f5d8f3f Mon Sep 17 00:00:00 2001 From: Nathan <148575555+nathan-artie@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:25:22 -0700 Subject: [PATCH] Use URI for MongoDB integration test (#514) --- .github/workflows/integration-tests.yaml | 2 +- integration_tests/mongo/main.go | 20 ++++++-------------- integration_tests/mysql/main.go | 2 ++ integration_tests/postgres/main.go | 2 ++ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index b2d4999f..1b9c58b6 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -63,4 +63,4 @@ jobs: with: go-version: 1.23 - name: Run integration test - run: MONGO_HOST=mongodb://mongo make mongo-itest + run: MONGO_HOST=mongo make mongo-itest diff --git a/integration_tests/mongo/main.go b/integration_tests/mongo/main.go index ed78eac0..fd5b0437 100644 --- a/integration_tests/mongo/main.go +++ b/integration_tests/mongo/main.go @@ -1,6 +1,7 @@ package main import ( + "cmp" "context" "encoding/json" "fmt" @@ -29,25 +30,14 @@ func main() { logger.Fatal("Unable to set TZ env var: %w", err) } - var mongoHost = os.Getenv("MONGO_HOST") - if mongoHost == "" { - mongoHost = "mongodb://localhost" - } - + var mongoHost = cmp.Or(os.Getenv("MONGO_HOST"), "localhost") mongoCfg := config.MongoDB{ - Host: fmt.Sprintf("%s:27017", mongoHost), - Username: "root", - Password: "example", + URI: fmt.Sprintf("mongodb://root:example@%s:27017", mongoHost), Database: "test", } - creds := options.Credential{ - Username: mongoCfg.Username, - Password: mongoCfg.Password, - } - // Not using TLS - opts := options.Client().ApplyURI(mongoCfg.Host).SetAuth(creds) + opts := options.Client().ApplyURI(mongoCfg.URI) ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second)) defer cancel() @@ -60,6 +50,8 @@ func main() { if err = testTypes(ctx, db, mongoCfg); err != nil { logger.Fatal("Types test failed", slog.Any("err", err)) } + + slog.Info("Test succeeded 😎") } func readTable(db *mongo.Database, collection config.Collection, cfg config.MongoDB) ([]lib.RawMessage, error) { diff --git a/integration_tests/mysql/main.go b/integration_tests/mysql/main.go index 504f5fcc..6ddfe61f 100644 --- a/integration_tests/mysql/main.go +++ b/integration_tests/mysql/main.go @@ -56,6 +56,8 @@ func main() { if err = testScan(db, mysqlCfg.Database); err != nil { logger.Fatal("Scan test failed", slog.Any("err", err)) } + + slog.Info("Test succeeded 😎") } func readTable(db *sql.DB, dbName, tableName string, batchSize int) ([]lib.RawMessage, error) { diff --git a/integration_tests/postgres/main.go b/integration_tests/postgres/main.go index 6c97aacc..81e14988 100644 --- a/integration_tests/postgres/main.go +++ b/integration_tests/postgres/main.go @@ -51,6 +51,8 @@ func main() { if err = testPrimaryKeyTypes(db); err != nil { logger.Fatal("Primary key types test failed", slog.Any("err", err)) } + + slog.Info("Test succeeded 😎") } func readTable(db *sql.DB, tableName string, batchSize int) ([]lib.RawMessage, error) {