Testcontainers-Go Common Image Registry
Common Image Registry for Testcontainers-Go
Prerequisites
Go >= 1.16
Install
go get github.com/nhatthm/testcontainers-go-registry
MySQL
package example
import (
"context"
testcontainersmysql "github.com/nhatthm/testcontainers-go-registry/sql/mysql"
testcontainers "github.com/nhatthm/testcontainers-go-extra"
)
const (
dbName = "test"
dbUser = "test"
dbPassword = "test"
migrationSource = "file://./resources/migrations/"
)
func startMySQL() (testcontainers.Container, error) {
return testcontainersmysql.StartGenericContainer(context.Background(),
dbName, dbUser, dbPassword,
testcontainersmysql.RunMigrations(migrationSource),
)
}
Postgres
package example
import (
"context"
testcontainerspostgres "github.com/nhatthm/testcontainers-go-registry/sql/postgres"
testcontainers "github.com/nhatthm/testcontainers-go-extra"
)
const (
dbName = "test"
dbUser = "test"
dbPassword = "test"
migrationSource = "file://./resources/migrations/"
)
func startMySQL() (testcontainers.Container, error) {
return testcontainerspostgres.StartGenericContainer(context.Background(),
dbName, dbUser, dbPassword,
testcontainerspostgres.RunMigrations(migrationSource),
)
}
Donation
If this project help you reduce time to develop, you can give me a cup of coffee :)
Paypal donation
or scan this