From ecb227ab5762daae98d28b6f101f6669c3a3aa05 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Mon, 6 Oct 2025 13:18:16 +0200 Subject: [PATCH 1/6] attempt to fix mongodump by using official image and adding mongodb-database-tools on the fly --- test/deploy/mongodb/Dockerfile | 4 +++ test/pkg/source/internal/testcommons.go | 37 +++++++++++++++++++++ test/pkg/source/mongodbtest/mongodb_test.go | 12 ++++--- 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 test/deploy/mongodb/Dockerfile diff --git a/test/deploy/mongodb/Dockerfile b/test/deploy/mongodb/Dockerfile new file mode 100644 index 0000000..644d079 --- /dev/null +++ b/test/deploy/mongodb/Dockerfile @@ -0,0 +1,4 @@ +FROM docker.io/mongo:latest +RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y mongodb-database-tools +# test if the tools are installed +RUN mongodump --version && mongorestore --version diff --git a/test/pkg/source/internal/testcommons.go b/test/pkg/source/internal/testcommons.go index d2a7b45..e9c9c00 100644 --- a/test/pkg/source/internal/testcommons.go +++ b/test/pkg/source/internal/testcommons.go @@ -6,7 +6,10 @@ import ( "io" "os" "os/exec" + "path/filepath" + "runtime" "strings" + "sync" "github.com/pkg/errors" "github.com/spf13/viper" @@ -18,6 +21,40 @@ import ( const ResticPort = "8000/tcp" const ResticPassword = "resticRepo" +var ( + projectRootOnce sync.Once + projectRoot string + projectRootErr error +) + +// ProjectRoot returns the repository root as determined by the location of go.mod relative to this file. +func ProjectRoot() string { + projectRootOnce.Do(func() { + _, thisFile, _, ok := runtime.Caller(0) + if !ok { + projectRootErr = errors.New("unable to determine caller for project root lookup") + return + } + dir := filepath.Dir(thisFile) + for { + if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil { + projectRoot = dir + return + } + parent := filepath.Dir(dir) + if parent == dir { + projectRootErr = errors.New("go.mod not found while searching for project root") + return + } + dir = parent + } + }) + if projectRootErr != nil { + panic(projectRootErr) + } + return projectRoot +} + // TestContainerSetup is a wrapper for testcontainers that gives easy access to container-address and container-port type TestContainerSetup struct { Container testcontainers.Container diff --git a/test/pkg/source/mongodbtest/mongodb_test.go b/test/pkg/source/mongodbtest/mongodb_test.go index 41326cc..57f5a14 100644 --- a/test/pkg/source/mongodbtest/mongodb_test.go +++ b/test/pkg/source/mongodbtest/mongodb_test.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "os" + "path/filepath" "testing" "github.com/mittwald/brudi/pkg/source" @@ -29,7 +30,6 @@ const dumpKind = "mongodump" const restoreKind = "mongorestore" const dbName = "test" const collName = "testColl" -const mongoImage = "docker.io/bitnami/mongodb:latest" const logString = "Waiting for connections" type MongoDumpAndRestoreTestSuite struct { @@ -240,11 +240,15 @@ func mongoDoRestore( // mongorequest is a testcontainers.ContainerRequest for a basic mongodb testcontainer var mongoRequest = testcontainers.ContainerRequest{ - Image: mongoImage, + FromDockerfile: testcontainers.FromDockerfile{ + Context: filepath.Join(commons.ProjectRoot(), "/test/deploy/mongodb"), + Dockerfile: "./Dockerfile", + PrintBuildLog: true, + }, ExposedPorts: []string{mongoPort}, Env: map[string]string{ - "MONGODB_ROOT_USERNAME": mongoUser, - "MONGODB_ROOT_PASSWORD": mongoPW, + "MONGO_INITDB_ROOT_USERNAME": mongoUser, + "MONGO_INITDB_ROOT_PASSWORD": mongoPW, }, WaitingFor: wait.ForLog(logString), } From 13e2a4a7a7174895f691204fd8dba272a4c8a501 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Mon, 6 Oct 2025 13:29:35 +0200 Subject: [PATCH 2/6] try to use official image --- test/pkg/source/mongodbtest/mongodb_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/pkg/source/mongodbtest/mongodb_test.go b/test/pkg/source/mongodbtest/mongodb_test.go index 57f5a14..009d8e5 100644 --- a/test/pkg/source/mongodbtest/mongodb_test.go +++ b/test/pkg/source/mongodbtest/mongodb_test.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "os" - "path/filepath" "testing" "github.com/mittwald/brudi/pkg/source" @@ -30,6 +29,7 @@ const dumpKind = "mongodump" const restoreKind = "mongorestore" const dbName = "test" const collName = "testColl" +const mongoImage = "docker.io/mongo:latest" const logString = "Waiting for connections" type MongoDumpAndRestoreTestSuite struct { @@ -240,11 +240,7 @@ func mongoDoRestore( // mongorequest is a testcontainers.ContainerRequest for a basic mongodb testcontainer var mongoRequest = testcontainers.ContainerRequest{ - FromDockerfile: testcontainers.FromDockerfile{ - Context: filepath.Join(commons.ProjectRoot(), "/test/deploy/mongodb"), - Dockerfile: "./Dockerfile", - PrintBuildLog: true, - }, + Image: mongoImage, ExposedPorts: []string{mongoPort}, Env: map[string]string{ "MONGO_INITDB_ROOT_USERNAME": mongoUser, From 4eca4f156746a63a698aa1719db6af0e7c286b18 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Mon, 6 Oct 2025 13:42:42 +0200 Subject: [PATCH 3/6] attempt to fix mysql test by using official image --- test/pkg/source/mysqltest/mysql_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/pkg/source/mysqltest/mysql_test.go b/test/pkg/source/mysqltest/mysql_test.go index 11f3c87..4e45410 100644 --- a/test/pkg/source/mysqltest/mysql_test.go +++ b/test/pkg/source/mysqltest/mysql_test.go @@ -39,8 +39,8 @@ const tableName = "testTable" // mysql and psql are a bit picky when it comes to localhost, use ip instead const hostName = "127.0.0.1" -const logString = "** Starting MySQL **" -const mysqlImage = "docker.io/bitnami/mysql:5.7" +const logString = "ready for connections" +const mysqlImage = "docker.io/mysql:5.7" type MySQLDumpAndRestoreTestSuite struct { suite.Suite @@ -461,8 +461,6 @@ var mySQLRequest = testcontainers.ContainerRequest{ "MYSQL_DATABASE": mySQLDatabase, "MYSQL_USER": mySQLUser, "MYSQL_PASSWORD": mySQLPw, - "JDBC_PARAMS": "useSSL=false", - "MYSQL_EXTRA_FLAGS": "--default-authentication-plugin=mysql_native_password --skip-ssl", }, WaitingFor: wait.ForLog(logString), } From 1748e5e09ad655d67bc5b592c5d04499647af1e7 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Mon, 6 Oct 2025 13:54:23 +0200 Subject: [PATCH 4/6] attempt to fix postgres test by using official image --- test/pkg/source/postgrestest/postgres_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pkg/source/postgrestest/postgres_test.go b/test/pkg/source/postgrestest/postgres_test.go index 33b78ba..f4f15a1 100644 --- a/test/pkg/source/postgrestest/postgres_test.go +++ b/test/pkg/source/postgrestest/postgres_test.go @@ -38,7 +38,7 @@ const dumpKind = "pgdump" // mysql and psql are a bit picky when it comes to localhost, use ip instead const hostName = "127.0.0.1" const dbDriver = "pgx" -const pgImage = "docker.io/bitnami/postgresql:17" +const pgImage = "docker.io/postgresql:17" const plainKind = "plain" type PGDumpAndRestoreTestSuite struct { From c6605fe27ad3a86ad68f7918716d753f15062b1f Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Mon, 6 Oct 2025 14:01:07 +0200 Subject: [PATCH 5/6] fix postgres image url --- test/pkg/source/postgrestest/postgres_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pkg/source/postgrestest/postgres_test.go b/test/pkg/source/postgrestest/postgres_test.go index f4f15a1..fe24812 100644 --- a/test/pkg/source/postgrestest/postgres_test.go +++ b/test/pkg/source/postgrestest/postgres_test.go @@ -38,7 +38,7 @@ const dumpKind = "pgdump" // mysql and psql are a bit picky when it comes to localhost, use ip instead const hostName = "127.0.0.1" const dbDriver = "pgx" -const pgImage = "docker.io/postgresql:17" +const pgImage = "docker.io/postgres:17" const plainKind = "plain" type PGDumpAndRestoreTestSuite struct { From 07ad3437130e524643b952f17b4b37ec93b901b3 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Mon, 6 Oct 2025 14:14:02 +0200 Subject: [PATCH 6/6] remove dockerfile --- test/deploy/mongodb/Dockerfile | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 test/deploy/mongodb/Dockerfile diff --git a/test/deploy/mongodb/Dockerfile b/test/deploy/mongodb/Dockerfile deleted file mode 100644 index 644d079..0000000 --- a/test/deploy/mongodb/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM docker.io/mongo:latest -RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y mongodb-database-tools -# test if the tools are installed -RUN mongodump --version && mongorestore --version