diff --git a/flow/e2e/bigquery/peer_flow_bq_test.go b/flow/e2e/bigquery/peer_flow_bq_test.go index 83f51879c0..c76ea2c3dc 100644 --- a/flow/e2e/bigquery/peer_flow_bq_test.go +++ b/flow/e2e/bigquery/peer_flow_bq_test.go @@ -31,7 +31,19 @@ type PeerFlowE2ETestSuiteBQ struct { } func TestPeerFlowE2ETestSuiteBQ(t *testing.T) { - got.Each(t, e2eshared.GotSuite(setupSuite)) + e2eshared.GotSuite(t, setupSuite, func(s PeerFlowE2ETestSuiteBQ) { + err := e2e.TearDownPostgres(s.pool, s.bqSuffix) + if err != nil { + slog.Error("failed to tear down postgres", slog.Any("error", err)) + s.FailNow() + } + + err = s.bqHelper.DropDataset(s.bqHelper.datasetName) + if err != nil { + slog.Error("failed to tear down bigquery", slog.Any("error", err)) + s.FailNow() + } + }) } func (s PeerFlowE2ETestSuiteBQ) attachSchemaSuffix(tableName string) string { @@ -136,20 +148,6 @@ func setupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuiteBQ { } } -func (s PeerFlowE2ETestSuiteBQ) TearDownSuite() { - err := e2e.TearDownPostgres(s.pool, s.bqSuffix) - if err != nil { - slog.Error("failed to tear down postgres", slog.Any("error", err)) - s.FailNow() - } - - err = s.bqHelper.DropDataset(s.bqHelper.datasetName) - if err != nil { - slog.Error("failed to tear down bigquery", slog.Any("error", err)) - s.FailNow() - } -} - func (s PeerFlowE2ETestSuiteBQ) Test_Invalid_Connection_Config() { env := e2e.NewTemporalTestWorkflowEnvironment() e2e.RegisterWorkflowsAndActivities(s.t, env) diff --git a/flow/e2e/snowflake/peer_flow_sf_test.go b/flow/e2e/snowflake/peer_flow_sf_test.go index d1d5e3043e..2f02723d5d 100644 --- a/flow/e2e/snowflake/peer_flow_sf_test.go +++ b/flow/e2e/snowflake/peer_flow_sf_test.go @@ -34,7 +34,28 @@ type PeerFlowE2ETestSuiteSF struct { } func TestPeerFlowE2ETestSuiteSF(t *testing.T) { - got.Each(t, e2eshared.GotSuite(SetupSuite)) + e2eshared.GotSuite(t, SetupSuite, func(s PeerFlowE2ETestSuiteSF) { + err := e2e.TearDownPostgres(s.pool, s.pgSuffix) + if err != nil { + slog.Error("failed to tear down Postgres", slog.Any("error", err)) + s.FailNow() + } + + if s.sfHelper != nil { + err = s.sfHelper.Cleanup() + if err != nil { + slog.Error("failed to tear down Snowflake", slog.Any("error", err)) + s.FailNow() + } + } + + err = s.connector.Close() + + if err != nil { + slog.Error("failed to close Snowflake connector", slog.Any("error", err)) + s.FailNow() + } + }) } func (s PeerFlowE2ETestSuiteSF) attachSchemaSuffix(tableName string) string { @@ -89,29 +110,6 @@ func SetupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuiteSF { return suite } -func (s PeerFlowE2ETestSuiteSF) TearDownSuite() { - err := e2e.TearDownPostgres(s.pool, s.pgSuffix) - if err != nil { - slog.Error("failed to tear down Postgres", slog.Any("error", err)) - s.FailNow() - } - - if s.sfHelper != nil { - err = s.sfHelper.Cleanup() - if err != nil { - slog.Error("failed to tear down Snowflake", slog.Any("error", err)) - s.FailNow() - } - } - - err = s.connector.Close() - - if err != nil { - slog.Error("failed to close Snowflake connector", slog.Any("error", err)) - s.FailNow() - } -} - func (s PeerFlowE2ETestSuiteSF) Test_Complete_Simple_Flow_SF() { env := e2e.NewTemporalTestWorkflowEnvironment() e2e.RegisterWorkflowsAndActivities(s.t, env) diff --git a/flow/e2e/snowflake/snowflake_schema_delta_test.go b/flow/e2e/snowflake/snowflake_schema_delta_test.go index cfe38093d3..693062e39d 100644 --- a/flow/e2e/snowflake/snowflake_schema_delta_test.go +++ b/flow/e2e/snowflake/snowflake_schema_delta_test.go @@ -59,13 +59,6 @@ func setupSchemaDeltaSuite( } } -func (suite SnowflakeSchemaDeltaTestSuite) TearDownSuite() { - err := suite.sfTestHelper.Cleanup() - suite.failTestError(err) - err = suite.connector.Close() - suite.failTestError(err) -} - func (suite SnowflakeSchemaDeltaTestSuite) TestSimpleAddColumn() { tableName := fmt.Sprintf("%s.SIMPLE_ADD_COLUMN", schemaDeltaTestSchemaName) err := suite.sfTestHelper.RunCommand(fmt.Sprintf("CREATE TABLE %s(ID TEXT PRIMARY KEY)", tableName)) @@ -223,5 +216,8 @@ func (suite SnowflakeSchemaDeltaTestSuite) TestAddWhitespaceColumnNames() { } func TestSnowflakeSchemaDeltaTestSuite(t *testing.T) { - got.Each(t, e2eshared.GotSuite(setupSchemaDeltaSuite)) + e2eshared.GotSuite(t, setupSchemaDeltaSuite, func(suite SnowflakeSchemaDeltaTestSuite) { + suite.failTestError(suite.sfTestHelper.Cleanup()) + suite.failTestError(suite.connector.Close()) + }) } diff --git a/flow/e2eshared/e2eshared.go b/flow/e2eshared/e2eshared.go index bc7d7bb60e..56b9ffc985 100644 --- a/flow/e2eshared/e2eshared.go +++ b/flow/e2eshared/e2eshared.go @@ -9,17 +9,19 @@ import ( "github.com/ysmood/got" ) -func GotSuite[T interface{ TearDownSuite() }](setup func(t *testing.T, g got.G) T) func(t *testing.T) T { - return func(t *testing.T) T { +func GotSuite[T any](t *testing.T, setup func(t *testing.T, g got.G) T, teardown func(T)) { + t.Helper() + + got.Each(t, func(t *testing.T) T { t.Helper() g := got.New(t) g.Parallel() suite := setup(t, g) g.Cleanup(func() { - suite.TearDownSuite() + teardown(suite) }) return suite - } + }) } // ReadFileToBytes reads a file to a byte array.