Skip to content

Commit

Permalink
Use URI for MongoDB integration test (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie authored Oct 9, 2024
1 parent ffae007 commit 033c29c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 6 additions & 14 deletions integration_tests/mongo/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"cmp"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -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()

Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/mysql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/postgres/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 033c29c

Please sign in to comment.