mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 08:37:10 +08:00
chore: use cleanup function
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/testcontainers/testcontainers-go"
|
||||||
"github.com/testcontainers/testcontainers-go/modules/clickhouse"
|
"github.com/testcontainers/testcontainers-go/modules/clickhouse"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,14 +40,10 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) {
|
|||||||
clickhouse.WithPassword(clickhousePass),
|
clickhouse.WithPassword(clickhousePass),
|
||||||
clickhouse.WithDatabase(clickhouseDB),
|
clickhouse.WithDatabase(clickhouseDB),
|
||||||
)
|
)
|
||||||
|
testcontainers.CleanupContainer(t, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
t.Cleanup(func() {
|
|
||||||
if c != nil {
|
|
||||||
require.NoError(t, c.Terminate(ctx))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
hostPort, err := c.ConnectionHost(ctx)
|
hostPort, err := c.ConnectionHost(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/testcontainers/testcontainers-go"
|
||||||
"github.com/testcontainers/testcontainers-go/modules/couchbase"
|
"github.com/testcontainers/testcontainers-go/modules/couchbase"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,14 +37,10 @@ func newTestStore(t testing.TB) (*Storage, error) {
|
|||||||
couchbase.WithAdminCredentials(couchbaseUser, couchbasePass),
|
couchbase.WithAdminCredentials(couchbaseUser, couchbasePass),
|
||||||
couchbase.WithBuckets(bucket),
|
couchbase.WithBuckets(bucket),
|
||||||
)
|
)
|
||||||
|
testcontainers.CleanupContainer(t, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
t.Cleanup(func() {
|
|
||||||
if c != nil {
|
|
||||||
require.NoError(t, c.Terminate(ctx))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
conn, err := c.ConnectionString(ctx)
|
conn, err := c.ConnectionString(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/testcontainers/testcontainers-go"
|
||||||
"github.com/testcontainers/testcontainers-go/modules/minio"
|
"github.com/testcontainers/testcontainers-go/modules/minio"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,14 +35,10 @@ func newTestStore(t testing.TB) (*Storage, error) {
|
|||||||
minio.WithUsername(minioUser),
|
minio.WithUsername(minioUser),
|
||||||
minio.WithPassword(minioPass),
|
minio.WithPassword(minioPass),
|
||||||
)
|
)
|
||||||
|
testcontainers.CleanupContainer(t, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
t.Cleanup(func() {
|
|
||||||
if c != nil {
|
|
||||||
require.NoError(t, c.Terminate(ctx))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
conn, err := c.ConnectionString(ctx)
|
conn, err := c.ConnectionString(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/testcontainers/testcontainers-go"
|
||||||
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,14 +30,10 @@ func newTestStore(t testing.TB) (*Storage, error) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
c, err := mongodb.Run(ctx, img, mongodb.WithUsername(mongoDBUser), mongodb.WithPassword(mongoDBPass))
|
c, err := mongodb.Run(ctx, img, mongodb.WithUsername(mongoDBUser), mongodb.WithPassword(mongoDBPass))
|
||||||
|
testcontainers.CleanupContainer(t, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
t.Cleanup(func() {
|
|
||||||
if c != nil {
|
|
||||||
require.NoError(t, c.Terminate(ctx))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
conn, err := c.ConnectionString(ctx)
|
conn, err := c.ConnectionString(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/testcontainers/testcontainers-go"
|
||||||
"github.com/testcontainers/testcontainers-go/modules/mssql"
|
"github.com/testcontainers/testcontainers-go/modules/mssql"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,14 +36,10 @@ func newTestStore(t testing.TB) (*Storage, error) {
|
|||||||
mssql.WithPassword(mssqlPass),
|
mssql.WithPassword(mssqlPass),
|
||||||
mssql.WithAcceptEULA(),
|
mssql.WithAcceptEULA(),
|
||||||
)
|
)
|
||||||
|
testcontainers.CleanupContainer(t, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
t.Cleanup(func() {
|
|
||||||
if c != nil {
|
|
||||||
require.NoError(t, c.Terminate(ctx))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
conn, err := c.ConnectionString(ctx)
|
conn, err := c.ConnectionString(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/testcontainers/testcontainers-go"
|
||||||
"github.com/testcontainers/testcontainers-go/modules/mysql"
|
"github.com/testcontainers/testcontainers-go/modules/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,12 +52,8 @@ func mustStartMySQL(t testing.TB) *mysql.MySQLContainer {
|
|||||||
mysql.WithUsername(mysqlUser),
|
mysql.WithUsername(mysqlUser),
|
||||||
mysql.WithDatabase(mysqlDatabase),
|
mysql.WithDatabase(mysqlDatabase),
|
||||||
)
|
)
|
||||||
|
testcontainers.CleanupContainer(t, c)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Cleanup(func() {
|
|
||||||
if c != nil {
|
|
||||||
require.NoError(t, c.Terminate(ctx))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
@@ -42,12 +42,8 @@ func newTestStore(t testing.TB) (*Storage, error) {
|
|||||||
wait.ForLog("database system is ready to accept connections").WithOccurrence(2),
|
wait.ForLog("database system is ready to accept connections").WithOccurrence(2),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
testcontainers.CleanupContainer(t, c)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Cleanup(func() {
|
|
||||||
if c != nil {
|
|
||||||
require.NoError(t, c.Terminate(ctx))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
conn, err := c.ConnectionString(ctx, "sslmode=disable")
|
conn, err := c.ConnectionString(ctx, "sslmode=disable")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user