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..009d8e5 100644 --- a/test/pkg/source/mongodbtest/mongodb_test.go +++ b/test/pkg/source/mongodbtest/mongodb_test.go @@ -29,7 +29,7 @@ const dumpKind = "mongodump" const restoreKind = "mongorestore" const dbName = "test" const collName = "testColl" -const mongoImage = "docker.io/bitnami/mongodb:latest" +const mongoImage = "docker.io/mongo:latest" const logString = "Waiting for connections" type MongoDumpAndRestoreTestSuite struct { @@ -243,8 +243,8 @@ var mongoRequest = testcontainers.ContainerRequest{ Image: mongoImage, 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), } 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), } diff --git a/test/pkg/source/postgrestest/postgres_test.go b/test/pkg/source/postgrestest/postgres_test.go index 33b78ba..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/bitnami/postgresql:17" +const pgImage = "docker.io/postgres:17" const plainKind = "plain" type PGDumpAndRestoreTestSuite struct {