Skip to content

Commit

Permalink
Remove got
Browse files Browse the repository at this point in the history
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
  • Loading branch information
serprex committed Jan 3, 2024
1 parent 7f2862e commit d2bb043
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
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("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.
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 d2bb043

Please sign in to comment.