Skip to content
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
37 changes: 37 additions & 0 deletions test/pkg/source/internal/testcommons.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"sync"

"github.com/pkg/errors"
"github.com/spf13/viper"
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/pkg/source/mongodbtest/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}
Expand Down
6 changes: 2 additions & 4 deletions test/pkg/source/mysqltest/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
2 changes: 1 addition & 1 deletion test/pkg/source/postgrestest/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down