Skip to content

Commit

Permalink
chore: use cleanup function
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Dec 12, 2024
1 parent b074e83 commit cac4fd5
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 35 deletions.
7 changes: 2 additions & 5 deletions clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions couchbase/couchbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/couchbase"
)

Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions minio/minio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/minio"
)

Expand All @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions mongodb/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/mongodb"
)

Expand All @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions mssql/mssql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/mssql"
)

Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/mysql"
)

Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 1 addition & 5 deletions postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cac4fd5

Please sign in to comment.