Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use URI for MongoDB integration test #514

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 😎")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these so we know that the test is running to completion.

}

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