From cac4fd5e8d34d146fe8e9fa2ee9d14bb5cd81386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 12 Dec 2024 12:12:56 +0100 Subject: [PATCH] chore: use cleanup function --- clickhouse/clickhouse_test.go | 7 ++----- couchbase/couchbase_test.go | 7 ++----- minio/minio_test.go | 7 ++----- mongodb/mongodb_test.go | 7 ++----- mssql/mssql_test.go | 7 ++----- mysql/mysql_test.go | 7 ++----- postgres/postgres_test.go | 6 +----- 7 files changed, 13 insertions(+), 35 deletions(-) diff --git a/clickhouse/clickhouse_test.go b/clickhouse/clickhouse_test.go index 6c91180f..30073f36 100644 --- a/clickhouse/clickhouse_test.go +++ b/clickhouse/clickhouse_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/clickhouse" ) @@ -39,14 +40,10 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) { clickhouse.WithPassword(clickhousePass), clickhouse.WithDatabase(clickhouseDB), ) + testcontainers.CleanupContainer(t, c) if err != nil { return nil, err } - t.Cleanup(func() { - if c != nil { - require.NoError(t, c.Terminate(ctx)) - } - }) hostPort, err := c.ConnectionHost(ctx) if err != nil { diff --git a/couchbase/couchbase_test.go b/couchbase/couchbase_test.go index 1f29b4ff..dd8b6ed6 100644 --- a/couchbase/couchbase_test.go +++ b/couchbase/couchbase_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/couchbase" ) @@ -36,14 +37,10 @@ func newTestStore(t testing.TB) (*Storage, error) { couchbase.WithAdminCredentials(couchbaseUser, couchbasePass), couchbase.WithBuckets(bucket), ) + testcontainers.CleanupContainer(t, c) if err != nil { return nil, err } - t.Cleanup(func() { - if c != nil { - require.NoError(t, c.Terminate(ctx)) - } - }) conn, err := c.ConnectionString(ctx) if err != nil { diff --git a/minio/minio_test.go b/minio/minio_test.go index f0890385..93f62a5e 100644 --- a/minio/minio_test.go +++ b/minio/minio_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/minio" ) @@ -34,14 +35,10 @@ func newTestStore(t testing.TB) (*Storage, error) { minio.WithUsername(minioUser), minio.WithPassword(minioPass), ) + testcontainers.CleanupContainer(t, c) if err != nil { return nil, err } - t.Cleanup(func() { - if c != nil { - require.NoError(t, c.Terminate(ctx)) - } - }) conn, err := c.ConnectionString(ctx) if err != nil { diff --git a/mongodb/mongodb_test.go b/mongodb/mongodb_test.go index 019390ef..a5187aaa 100644 --- a/mongodb/mongodb_test.go +++ b/mongodb/mongodb_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" ) @@ -29,14 +30,10 @@ func newTestStore(t testing.TB) (*Storage, error) { ctx := context.Background() c, err := mongodb.Run(ctx, img, mongodb.WithUsername(mongoDBUser), mongodb.WithPassword(mongoDBPass)) + testcontainers.CleanupContainer(t, c) if err != nil { return nil, err } - t.Cleanup(func() { - if c != nil { - require.NoError(t, c.Terminate(ctx)) - } - }) conn, err := c.ConnectionString(ctx) if err != nil { diff --git a/mssql/mssql_test.go b/mssql/mssql_test.go index 24e2bfc2..0f7dfc33 100644 --- a/mssql/mssql_test.go +++ b/mssql/mssql_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mssql" ) @@ -35,14 +36,10 @@ func newTestStore(t testing.TB) (*Storage, error) { mssql.WithPassword(mssqlPass), mssql.WithAcceptEULA(), ) + testcontainers.CleanupContainer(t, c) if err != nil { return nil, err } - t.Cleanup(func() { - if c != nil { - require.NoError(t, c.Terminate(ctx)) - } - }) conn, err := c.ConnectionString(ctx) if err != nil { diff --git a/mysql/mysql_test.go b/mysql/mysql_test.go index 6462f201..57f268e4 100644 --- a/mysql/mysql_test.go +++ b/mysql/mysql_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mysql" ) @@ -51,12 +52,8 @@ func mustStartMySQL(t testing.TB) *mysql.MySQLContainer { mysql.WithUsername(mysqlUser), mysql.WithDatabase(mysqlDatabase), ) + testcontainers.CleanupContainer(t, c) require.NoError(t, err) - t.Cleanup(func() { - if c != nil { - require.NoError(t, c.Terminate(ctx)) - } - }) return c } diff --git a/postgres/postgres_test.go b/postgres/postgres_test.go index 2e9ff846..85383b4f 100644 --- a/postgres/postgres_test.go +++ b/postgres/postgres_test.go @@ -42,12 +42,8 @@ func newTestStore(t testing.TB) (*Storage, error) { wait.ForLog("database system is ready to accept connections").WithOccurrence(2), ), ) + testcontainers.CleanupContainer(t, c) require.NoError(t, err) - t.Cleanup(func() { - if c != nil { - require.NoError(t, c.Terminate(ctx)) - } - }) conn, err := c.ConnectionString(ctx, "sslmode=disable") if err != nil {