diff --git a/flow/connectors/postgres/postgres_schema_delta_test.go b/flow/connectors/postgres/postgres_schema_delta_test.go index 4fb16a26f7..8b72b46f20 100644 --- a/flow/connectors/postgres/postgres_schema_delta_test.go +++ b/flow/connectors/postgres/postgres_schema_delta_test.go @@ -235,7 +235,7 @@ func (s PostgresSchemaDeltaTestSuite) TestAddDropWhitespaceColumnNames() { } func TestPostgresSchemaDeltaTestSuite(t *testing.T) { - e2eshared.GotSuite(t, SetupSuite, func(s PostgresSchemaDeltaTestSuite) { + e2eshared.RunSuite(t, SetupSuite, func(s PostgresSchemaDeltaTestSuite) { teardownTx, err := s.connector.pool.Begin(context.Background()) require.NoError(s.t, err) defer func() { diff --git a/flow/e2e/bigquery/peer_flow_bq_test.go b/flow/e2e/bigquery/peer_flow_bq_test.go index 2bbc24c1b4..4fb20929b3 100644 --- a/flow/e2e/bigquery/peer_flow_bq_test.go +++ b/flow/e2e/bigquery/peer_flow_bq_test.go @@ -29,7 +29,7 @@ type PeerFlowE2ETestSuiteBQ struct { } func TestPeerFlowE2ETestSuiteBQ(t *testing.T) { - e2eshared.GotSuite(t, setupSuite, func(s PeerFlowE2ETestSuiteBQ) { + e2eshared.RunSuite(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)) diff --git a/flow/e2e/postgres/qrep_flow_pg_test.go b/flow/e2e/postgres/qrep_flow_pg_test.go index 8c27c52c8b..cf0eda3b03 100644 --- a/flow/e2e/postgres/qrep_flow_pg_test.go +++ b/flow/e2e/postgres/qrep_flow_pg_test.go @@ -29,7 +29,7 @@ type PeerFlowE2ETestSuitePG struct { } func TestPeerFlowE2ETestSuitePG(t *testing.T) { - e2eshared.GotSuite(t, SetupSuite, func(s PeerFlowE2ETestSuitePG) { + e2eshared.RunSuite(t, SetupSuite, func(s PeerFlowE2ETestSuitePG) { err := e2e.TearDownPostgres(s.pool, s.suffix) if err != nil { require.Fail(s.t, "failed to drop Postgres schema", err) diff --git a/flow/e2e/s3/qrep_flow_s3_test.go b/flow/e2e/s3/qrep_flow_s3_test.go index 38d9add502..68cc49fb44 100644 --- a/flow/e2e/s3/qrep_flow_s3_test.go +++ b/flow/e2e/s3/qrep_flow_s3_test.go @@ -37,11 +37,11 @@ func tearDownSuite(s PeerFlowE2ETestSuiteS3) { } func TestPeerFlowE2ETestSuiteS3(t *testing.T) { - e2eshared.GotSuite(t, SetupSuiteS3, tearDownSuite) + e2eshared.RunSuite(t, SetupSuiteS3, tearDownSuite) } func TestPeerFlowE2ETestSuiteGCS(t *testing.T) { - e2eshared.GotSuite(t, SetupSuiteGCS, tearDownSuite) + e2eshared.RunSuite(t, SetupSuiteGCS, tearDownSuite) } func (s PeerFlowE2ETestSuiteS3) setupSourceTable(tableName string, rowCount int) { diff --git a/flow/e2e/snowflake/peer_flow_sf_test.go b/flow/e2e/snowflake/peer_flow_sf_test.go index c47c8964dc..818bf56d21 100644 --- a/flow/e2e/snowflake/peer_flow_sf_test.go +++ b/flow/e2e/snowflake/peer_flow_sf_test.go @@ -31,7 +31,7 @@ type PeerFlowE2ETestSuiteSF struct { } func TestPeerFlowE2ETestSuiteSF(t *testing.T) { - e2eshared.GotSuite(t, SetupSuite, func(s PeerFlowE2ETestSuiteSF) { + e2eshared.RunSuite(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)) diff --git a/flow/e2e/snowflake/snowflake_schema_delta_test.go b/flow/e2e/snowflake/snowflake_schema_delta_test.go index 60d8d99574..f9f0c1ceca 100644 --- a/flow/e2e/snowflake/snowflake_schema_delta_test.go +++ b/flow/e2e/snowflake/snowflake_schema_delta_test.go @@ -216,7 +216,7 @@ func (s SnowflakeSchemaDeltaTestSuite) TestAddWhitespaceColumnNames() { } func TestSnowflakeSchemaDeltaTestSuite(t *testing.T) { - e2eshared.GotSuite(t, setupSchemaDeltaSuite, func(s SnowflakeSchemaDeltaTestSuite) { + e2eshared.RunSuite(t, setupSchemaDeltaSuite, func(s SnowflakeSchemaDeltaTestSuite) { require.NoError(s.t, s.sfTestHelper.Cleanup()) require.NoError(s.t, s.connector.Close()) }) diff --git a/flow/e2e/sqlserver/qrep_flow_sqlserver_test.go b/flow/e2e/sqlserver/qrep_flow_sqlserver_test.go index 32df9e2c6c..25f11dfc44 100644 --- a/flow/e2e/sqlserver/qrep_flow_sqlserver_test.go +++ b/flow/e2e/sqlserver/qrep_flow_sqlserver_test.go @@ -30,7 +30,7 @@ type PeerFlowE2ETestSuiteSQLServer struct { } func TestCDCFlowE2ETestSuiteSQLServer(t *testing.T) { - e2eshared.GotSuite(t, SetupSuite, func(s PeerFlowE2ETestSuiteSQLServer) { + e2eshared.RunSuite(t, SetupSuite, func(s PeerFlowE2ETestSuiteSQLServer) { err := e2e.TearDownPostgres(s.pool, s.suffix) require.NoError(s.t, err) diff --git a/flow/e2eshared/e2eshared.go b/flow/e2eshared/e2eshared.go index 283499aa78..59b2087de4 100644 --- a/flow/e2eshared/e2eshared.go +++ b/flow/e2eshared/e2eshared.go @@ -4,27 +4,35 @@ import ( "fmt" "io" "os" + "reflect" + "strings" "testing" "github.com/PeerDB-io/peer-flow/model" - - "github.com/ysmood/got" ) -func GotSuite[T any](t *testing.T, setup func(t *testing.T) T, teardown func(T)) { +func RunSuite[T any](t *testing.T, setup func(t *testing.T) T, teardown func(T)) { t.Helper() t.Parallel() - got.Each(t, func(t *testing.T) T { - t.Helper() - g := got.New(t) - g.Parallel() - suite := setup(t) - g.Cleanup(func() { - teardown(suite) - }) - return suite - }) + // can be replaced with reflect.TypeFor[T]() in go 1.22 + typ := reflect.TypeOf((*T)(nil)).Elem() + mcount := typ.NumMethod() + for i := 0; i < mcount; i++ { + m := typ.Method(i) + if strings.HasPrefix(m.Name, "Test") { + if m.Type.NumIn() == 1 && m.Type.NumOut() == 0 { + t.Run(m.Name, func(subtest *testing.T) { + subtest.Parallel() + suite := setup(subtest) + subtest.Cleanup(func() { + teardown(suite) + }) + m.Func.Call([]reflect.Value{reflect.ValueOf(suite)}) + }) + } + } + } } // ReadFileToBytes reads a file to a byte array. diff --git a/flow/go.mod b/flow/go.mod index 2b1b0d4d91..66e9991c72 100644 --- a/flow/go.mod +++ b/flow/go.mod @@ -31,7 +31,6 @@ require ( github.com/twpayne/go-geos v0.14.0 github.com/urfave/cli/v3 v3.0.0-alpha8 github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a - github.com/ysmood/got v0.38.3 go.temporal.io/api v1.26.0 go.temporal.io/sdk v1.25.1 go.uber.org/atomic v1.11.0 @@ -66,7 +65,6 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - github.com/ysmood/gop v0.2.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect go.opentelemetry.io/otel v1.21.0 // indirect diff --git a/flow/go.sum b/flow/go.sum index 767944d3c1..c53c018ad2 100644 --- a/flow/go.sum +++ b/flow/go.sum @@ -385,10 +385,6 @@ github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e h1:+SOyEddqYF09QP7v github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4= -github.com/ysmood/gop v0.2.0 h1:+tFrG0TWPxT6p9ZaZs+VY+opCvHU8/3Fk6BaNv6kqKg= -github.com/ysmood/gop v0.2.0/go.mod h1:rr5z2z27oGEbyB787hpEcx4ab8cCiPnKxn0SUHt6xzk= -github.com/ysmood/got v0.38.3 h1:yGvt4EnVbwK2k1jjz73ztT47f/RrqHWGUMxGx6Vvu9w= -github.com/ysmood/got v0.38.3/go.mod h1:W7DdpuX6skL3NszLmAsC5hT7JAhuLZhByVzHTq874Qg= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=