chore: split storage and container creation for better granularity in the suite hook

This commit is contained in:
Manuel de la Peña
2025-08-29 12:00:32 +02:00
parent 253aa04087
commit 511351b66f
2 changed files with 122 additions and 69 deletions

View File

@@ -26,11 +26,9 @@ const (
type MySQLStorageTCK struct{}
func (s *MySQLStorageTCK) NewStoreWithContainer() func(ctx context.Context, tb testing.TB) (*Storage, testcontainers.Container, error) {
return func(ctx context.Context, tb testing.TB) (*Storage, testcontainers.Container, error) {
c := mustStartMySQL(tb)
conn, err := c.ConnectionString(ctx)
func (s *MySQLStorageTCK) NewStore() func(ctx context.Context, tb testing.TB, ctr *mysql.MySQLContainer) (*Storage, error) {
return func(ctx context.Context, tb testing.TB, ctr *mysql.MySQLContainer) (*Storage, error) {
conn, err := ctr.ConnectionString(ctx)
require.NoError(tb, err)
store := New(Config{
@@ -38,7 +36,13 @@ func (s *MySQLStorageTCK) NewStoreWithContainer() func(ctx context.Context, tb t
Reset: true,
})
return store, c, nil
return store, nil
}
}
func (s *MySQLStorageTCK) NewContainer() func(ctx context.Context, tb testing.TB) (*mysql.MySQLContainer, error) {
return func(ctx context.Context, tb testing.TB) (*mysql.MySQLContainer, error) {
return mustStartMySQL(tb), nil
}
}
@@ -48,7 +52,11 @@ func newTestStore(t testing.TB) *Storage {
ctx := context.Background()
suite := MySQLStorageTCK{}
store, _, err := suite.NewStoreWithContainer()(ctx, t)
ctr, err := suite.NewContainer()(ctx, t)
require.NoError(t, err)
store, err := suite.NewStore()(ctx, t, ctr)
require.NoError(t, err)
return store