Skip to content

Commit

Permalink
Remove got (#978)
Browse files Browse the repository at this point in the history
got.Each calls all public methods, which was complicating making a Teardown method

I'm also looking to implement other interfaces to share code between packages,
which is complicated by got
  • Loading branch information
serprex authored Jan 3, 2024
1 parent 7f2862e commit ca4321e
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion flow/connectors/postgres/postgres_schema_delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion flow/e2e/bigquery/peer_flow_bq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion flow/e2e/postgres/qrep_flow_pg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions flow/e2e/s3/qrep_flow_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion flow/e2e/snowflake/peer_flow_sf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion flow/e2e/snowflake/snowflake_schema_delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
Expand Down
2 changes: 1 addition & 1 deletion flow/e2e/sqlserver/qrep_flow_sqlserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
34 changes: 21 additions & 13 deletions flow/e2eshared/e2eshared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions flow/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions flow/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit ca4321e

Please sign in to comment.