From d2bb04359cb7b0a16c1e7fb1221f61578f0818c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Wed, 3 Jan 2024 19:44:06 +0000 Subject: [PATCH] Remove got got.Each calls all 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 --- flow/e2eshared/e2eshared.go | 34 +++++++++++++++++++++------------- flow/go.mod | 2 -- flow/go.sum | 4 ---- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/flow/e2eshared/e2eshared.go b/flow/e2eshared/e2eshared.go index 283499aa78..71939de83a 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("Test", m.Name) { + 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=