diff --git a/database/mongo/container.go b/database/mongo/container.go deleted file mode 100644 index 6602394..0000000 --- a/database/mongo/container.go +++ /dev/null @@ -1,16 +0,0 @@ -package mongo - -import ( - "context" - - "go.nhat.io/testcontainers-extra" -) - -// StartGenericContainer starts a new mysql container. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mongo.StartGenericContainer instead. -func StartGenericContainer(ctx context.Context, opts ...testcontainers.GenericContainerOption) (testcontainers.Container, error) { - r := Request(opts...) - - return testcontainers.StartGenericContainer(ctx, r.Request, r.Options...) -} diff --git a/database/mongo/doc.go b/database/mongo/doc.go deleted file mode 100644 index 080a59d..0000000 --- a/database/mongo/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package mongo provides setup for spinning up a mongodb container. -package mongo diff --git a/database/mongo/request.go b/database/mongo/request.go deleted file mode 100644 index dc833eb..0000000 --- a/database/mongo/request.go +++ /dev/null @@ -1,49 +0,0 @@ -package mongo - -import ( - "fmt" - "time" - - _ "github.com/golang-migrate/migrate/v4/database/mongodb" // Database driver - "go.nhat.io/testcontainers-extra" - "go.nhat.io/testcontainers-extra/wait" - - db "go.nhat.io/testcontainers-registry/database" -) - -// Request creates a new request for starting a mongo server. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mongo.Request instead. -func Request(opts ...testcontainers.GenericContainerOption) testcontainers.StartGenericContainerRequest { - finalOpts := make([]testcontainers.GenericContainerOption, 1, len(opts)+1) - finalOpts[0] = testcontainers.PopulateHostPortEnv - finalOpts = append(finalOpts, opts...) - - return testcontainers.StartGenericContainerRequest{ - Request: testcontainers.ContainerRequest{ - Name: "mongo", - Image: "mongo:4.4", - ExposedPorts: []string{":27017"}, - WaitingFor: wait.ForHealthCheckCmd("mongo", "localhost:27017/test", "--quiet", "--eval", "'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'"). - WithRetries(3). - WithStartPeriod(15 * time.Second). - WithTestTimeout(5 * time.Second). - WithTestInterval(10 * time.Second), - }, - Options: finalOpts, - } -} - -// RunMigrations is option to run migrations. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mongo.RunMigrations instead. -func RunMigrations(migrationSource, dbName string) testcontainers.ContainerCallback { - return db.RunMigrations(migrationSource, DSN(dbName)) -} - -// DSN returns the database dsn for connecting to server. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mongo.DSN instead. -func DSN(dbName string) string { - return fmt.Sprintf("mongodb://$MONGO_27017_HOST:$MONGO_27017_PORT/%s", dbName) -} diff --git a/database/mssql/container.go b/database/mssql/container.go deleted file mode 100644 index 310b871..0000000 --- a/database/mssql/container.go +++ /dev/null @@ -1,16 +0,0 @@ -package mssql - -import ( - "context" - - "go.nhat.io/testcontainers-extra" -) - -// StartGenericContainer starts a new mssql container. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mssql.StartGenericContainer instead. -func StartGenericContainer(ctx context.Context, dbName, dbPassword string, opts ...testcontainers.GenericContainerOption) (testcontainers.Container, error) { - r := Request(dbName, dbPassword, opts...) - - return testcontainers.StartGenericContainer(ctx, r.Request, r.Options...) -} diff --git a/database/mssql/doc.go b/database/mssql/doc.go deleted file mode 100644 index fd80388..0000000 --- a/database/mssql/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package mssql provides setup for spinning up a mssql container. -package mssql diff --git a/database/mssql/request.go b/database/mssql/request.go deleted file mode 100644 index 1c8aa9f..0000000 --- a/database/mssql/request.go +++ /dev/null @@ -1,78 +0,0 @@ -package mssql - -import ( - "context" - "fmt" - "time" - - _ "github.com/golang-migrate/migrate/v4/database/sqlserver" // Database driver - "github.com/testcontainers/testcontainers-go/wait" - "go.nhat.io/testcontainers-extra" - extrawait "go.nhat.io/testcontainers-extra/wait" - - db "go.nhat.io/testcontainers-registry/database" -) - -// Request creates a new request for starting a mssql server. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mssql.Request instead. -func Request(dbName, dbPassword string, opts ...testcontainers.GenericContainerOption) testcontainers.StartGenericContainerRequest { - finalOpts := make([]testcontainers.GenericContainerOption, 2, len(opts)+2) - - finalOpts[0] = testcontainers.PopulateHostPortEnv - finalOpts[1] = testcontainers.WithCallback(func(ctx context.Context, c testcontainers.Container, _ testcontainers.ContainerRequest) error { - code, err := c.Exec(ctx, []string{ - "/opt/mssql-tools/bin/sqlcmd", "-S", "localhost", "-U", "sa", "-P", dbPassword, "-Q", `USE [master]; CREATE DATABASE ` + dbName + `;`, - }) - if err != nil { - return fmt.Errorf("could not create database: %w", err) - } - - if code > 0 { - return fmt.Errorf("could not create database (code %d)", code) // nolint: goerr113 - } - - return nil - }) - - finalOpts = append(finalOpts, opts...) - - return testcontainers.StartGenericContainerRequest{ - Request: testcontainers.ContainerRequest{ - Name: "mssql", - Image: "mcr.microsoft.com/mssql/server:2019-latest", - ExposedPorts: []string{":1433"}, - Env: map[string]string{ - "LC_ALL": "C.UTF-8", - "ACCEPT_EULA": "Y", - "SA_PASSWORD": dbPassword, - "MSSQL_PID": "Developer", - "MSSQL_DB": dbName, - }, - WaitingFor: wait.ForAll( - wait.ForLog("Recovery is complete"). - WithStartupTimeout(3*time.Minute), - extrawait.ForHealthCheckCmd("/opt/mssql-tools/bin/sqlcmd", "-S", "localhost", "-U", "sa", "-P", dbPassword, "-Q", `"SELECT 1"`). - WithRetries(3). - WithStartPeriod(5*time.Minute). - WithTestTimeout(5*time.Second). - WithTestInterval(10*time.Second), - ).WithStartupTimeout(10 * time.Minute), - }, - Options: finalOpts, - } -} - -// RunMigrations is option to run migrations. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mssql.RunMigrations instead. -func RunMigrations(migrationSource string) testcontainers.ContainerCallback { - return db.RunMigrations(migrationSource, DSN(`$MSSQL_DB`, `$SA_PASSWORD`)) -} - -// DSN returns the database dsn for connecting to server. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mssql.DSN instead. -func DSN(dbName, dbPassword string) string { - return fmt.Sprintf("sqlserver://sa:%s@$MSSQL_1433_HOST:$MSSQL_1433_PORT?database=%s", dbPassword, dbName) -} diff --git a/database/mysql/container.go b/database/mysql/container.go deleted file mode 100644 index 1d4d5ad..0000000 --- a/database/mysql/container.go +++ /dev/null @@ -1,16 +0,0 @@ -package mysql - -import ( - "context" - - "go.nhat.io/testcontainers-extra" -) - -// StartGenericContainer starts a new mysql container. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mysql.StartGenericContainer instead. -func StartGenericContainer(ctx context.Context, dbName, dbUser, dbPassword string, opts ...testcontainers.GenericContainerOption) (testcontainers.Container, error) { - r := Request(dbName, dbUser, dbPassword, opts...) - - return testcontainers.StartGenericContainer(ctx, r.Request, r.Options...) -} diff --git a/database/mysql/doc.go b/database/mysql/doc.go deleted file mode 100644 index fb89573..0000000 --- a/database/mysql/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package mysql provides setup for spinning up a mysql container. -package mysql diff --git a/database/mysql/request.go b/database/mysql/request.go deleted file mode 100644 index bf7c0ac..0000000 --- a/database/mysql/request.go +++ /dev/null @@ -1,61 +0,0 @@ -package mysql - -import ( - "fmt" - "time" - - _ "github.com/golang-migrate/migrate/v4/database/mysql" // Database driver - "github.com/testcontainers/testcontainers-go/wait" - "go.nhat.io/testcontainers-extra" - extrawait "go.nhat.io/testcontainers-extra/wait" - - db "go.nhat.io/testcontainers-registry/database" -) - -// Request creates a new request for starting a mysql server. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mysql.Request instead. -func Request(dbName, dbUser, dbPassword string, opts ...testcontainers.GenericContainerOption) testcontainers.StartGenericContainerRequest { - finalOpts := make([]testcontainers.GenericContainerOption, 1, len(opts)+1) - finalOpts[0] = testcontainers.PopulateHostPortEnv - finalOpts = append(finalOpts, opts...) - - return testcontainers.StartGenericContainerRequest{ - Request: testcontainers.ContainerRequest{ - Name: "mysql", - Image: "mysql:8", - ExposedPorts: []string{":3306"}, - Env: map[string]string{ - "LC_ALL": "C.UTF-8", - "MYSQL_DATABASE": dbName, - "MYSQL_USER": dbUser, - "MYSQL_PASSWORD": dbPassword, - "MYSQL_ROOT_PASSWORD": dbPassword, - }, - WaitingFor: wait.ForAll( - wait.ForLog("init process done. Ready for start up"). - WithStartupTimeout(5*time.Minute), - extrawait.ForHealthCheckCmd("mysqladmin", "ping", "-h", "localhost"). - WithRetries(3). - WithStartPeriod(5*time.Minute). - WithTestTimeout(5*time.Second). - WithTestInterval(10*time.Second), - ).WithStartupTimeout(10 * time.Minute), - }, - Options: finalOpts, - } -} - -// RunMigrations is option to run migrations. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mysql.RunMigrations instead. -func RunMigrations(migrationSource string) testcontainers.ContainerCallback { - return db.RunMigrations(migrationSource, fmt.Sprintf("mysql://%s", DSN(`$MYSQL_DATABASE`, `$MYSQL_USER`, `$MYSQL_PASSWORD`))) -} - -// DSN returns the database dsn for connecting to server. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/mysql.DSN instead. -func DSN(dbName, dbUser, dbPassword string) string { - return fmt.Sprintf("%s:%s@tcp($MYSQL_3306_HOST:$MYSQL_3306_PORT)/%s?charset=utf8&parseTime=true", dbUser, dbPassword, dbName) -} diff --git a/database/postgres/container.go b/database/postgres/container.go deleted file mode 100644 index bc420ea..0000000 --- a/database/postgres/container.go +++ /dev/null @@ -1,16 +0,0 @@ -package postgres - -import ( - "context" - - "go.nhat.io/testcontainers-extra" -) - -// StartGenericContainer starts a new mysql container. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/postgres.StartGenericContainer instead. -func StartGenericContainer(ctx context.Context, dbName, dbUser, dbPassword string, opts ...testcontainers.GenericContainerOption) (testcontainers.Container, error) { - r := Request(dbName, dbUser, dbPassword, opts...) - - return testcontainers.StartGenericContainer(ctx, r.Request, r.Options...) -} diff --git a/database/postgres/doc.go b/database/postgres/doc.go deleted file mode 100644 index abdf510..0000000 --- a/database/postgres/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package postgres provides setup for spinning up a postgres container. -package postgres diff --git a/database/postgres/request.go b/database/postgres/request.go deleted file mode 100644 index a2d155f..0000000 --- a/database/postgres/request.go +++ /dev/null @@ -1,55 +0,0 @@ -package postgres - -import ( - "fmt" - "time" - - _ "github.com/golang-migrate/migrate/v4/database/postgres" // Database driver - "go.nhat.io/testcontainers-extra" - "go.nhat.io/testcontainers-extra/wait" - - db "go.nhat.io/testcontainers-registry/database" -) - -// Request creates a new request for starting a postgres server. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/postgres.Request instead. -func Request(dbName, dbUser, dbPassword string, opts ...testcontainers.GenericContainerOption) testcontainers.StartGenericContainerRequest { - finalOpts := make([]testcontainers.GenericContainerOption, 1, len(opts)+1) - finalOpts[0] = testcontainers.PopulateHostPortEnv - finalOpts = append(finalOpts, opts...) - - return testcontainers.StartGenericContainerRequest{ - Request: testcontainers.ContainerRequest{ - Name: "postgres", - Image: "postgres:12-alpine", - ExposedPorts: []string{":5432"}, - Env: map[string]string{ - "LC_ALL": "C.UTF-8", - "POSTGRES_DB": dbName, - "POSTGRES_USER": dbUser, - "POSTGRES_PASSWORD": dbPassword, - }, - WaitingFor: wait.ForHealthCheckCmd("pg_isready"). - WithRetries(3). - WithStartPeriod(15 * time.Second). - WithTestTimeout(5 * time.Second). - WithTestInterval(10 * time.Second), - }, - Options: finalOpts, - } -} - -// RunMigrations is option to run migrations. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/postgres.RunMigrations instead. -func RunMigrations(migrationSource string) testcontainers.ContainerCallback { - return db.RunMigrations(migrationSource, DSN(`$POSTGRES_DB`, `$POSTGRES_USER`, `$POSTGRES_PASSWORD`)) -} - -// DSN returns the database dsn for connecting to server. -// -// Deprecated: Use go.nhat.io/testcontainers-registry/postgres.DSN instead. -func DSN(dbName, dbUser, dbPassword string) string { - return fmt.Sprintf("postgres://%s:%s@$POSTGRES_5432_HOST:$POSTGRES_5432_PORT/%s?sslmode=disable&client_encoding=UTF8", dbUser, dbPassword, dbName) -}