Skip to content

Commit

Permalink
Use URI for MongoDB integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Oct 9, 2024
1 parent ffae007 commit c71ba58
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
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 c71ba58

Please sign in to comment.