diff options
Diffstat (limited to 'internal')
79 files changed, 719 insertions, 174 deletions
diff --git a/internal/safe/main_test.go b/internal/backoff/testhelper_test.go index 64ba6b23e..cc3edbe5d 100644 --- a/internal/safe/main_test.go +++ b/internal/backoff/testhelper_test.go @@ -1,4 +1,4 @@ -package safe_test +package backoff import ( "testing" diff --git a/internal/blackbox/testhelper_test.go b/internal/blackbox/testhelper_test.go new file mode 100644 index 000000000..e88e9446d --- /dev/null +++ b/internal/blackbox/testhelper_test.go @@ -0,0 +1,11 @@ +package blackbox + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/bootstrap/starter/testhelper_test.go b/internal/bootstrap/starter/testhelper_test.go new file mode 100644 index 000000000..ab294fdf6 --- /dev/null +++ b/internal/bootstrap/starter/testhelper_test.go @@ -0,0 +1,11 @@ +package starter + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/cgroups/cgroups_linux_test.go b/internal/cgroups/cgroups_linux_test.go index 028d4bcd7..9abcf8cb4 100644 --- a/internal/cgroups/cgroups_linux_test.go +++ b/internal/cgroups/cgroups_linux_test.go @@ -10,10 +10,6 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" ) -func TestMain(m *testing.M) { - testhelper.Run(m) -} - func TestNewManager(t *testing.T) { require.IsType(t, &NoopManager{}, NewManager(cgroups.Config{}, testhelper.NewDiscardingLogEntry(t), 1)) } diff --git a/internal/cgroups/testhelper_test.go b/internal/cgroups/testhelper_test.go new file mode 100644 index 000000000..5f594195a --- /dev/null +++ b/internal/cgroups/testhelper_test.go @@ -0,0 +1,13 @@ +//go:build linux + +package cgroups + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/cli/praefect/main_test.go b/internal/cli/praefect/main_test.go index 4137c5277..42e764496 100644 --- a/internal/cli/praefect/main_test.go +++ b/internal/cli/praefect/main_test.go @@ -9,29 +9,12 @@ import ( "github.com/pelletier/go-toml/v2" "github.com/stretchr/testify/require" - "github.com/urfave/cli/v2" "gitlab.com/gitlab-org/gitaly/v16/internal/bootstrap/starter" "gitlab.com/gitlab-org/gitaly/v16/internal/helper/perm" "gitlab.com/gitlab-org/gitaly/v16/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" ) -func TestMain(m *testing.M) { - defer func(old func(code int)) { cli.OsExiter = old }(cli.OsExiter) - cli.OsExiter = func(code int) {} - - defer func(old cli.Flag) { cli.BashCompletionFlag = old }(cli.BashCompletionFlag) - cli.BashCompletionFlag = stubFlag{} - - defer func(old cli.Flag) { cli.VersionFlag = old }(cli.VersionFlag) - cli.VersionFlag = stubFlag{} - - defer func(old cli.Flag) { cli.HelpFlag = old }(cli.HelpFlag) - cli.HelpFlag = stubFlag{} - - testhelper.Run(m) -} - type stubFlag struct{} func (stubFlag) String() string { return "it is a stub" } diff --git a/internal/cli/praefect/testhelper_test.go b/internal/cli/praefect/testhelper_test.go new file mode 100644 index 000000000..9817ac4d5 --- /dev/null +++ b/internal/cli/praefect/testhelper_test.go @@ -0,0 +1,24 @@ +package praefect + +import ( + "testing" + + "github.com/urfave/cli/v2" + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + defer func(old func(code int)) { cli.OsExiter = old }(cli.OsExiter) + cli.OsExiter = func(code int) {} + + defer func(old cli.Flag) { cli.BashCompletionFlag = old }(cli.BashCompletionFlag) + cli.BashCompletionFlag = stubFlag{} + + defer func(old cli.Flag) { cli.VersionFlag = old }(cli.VersionFlag) + cli.VersionFlag = stubFlag{} + + defer func(old cli.Flag) { cli.HelpFlag = old }(cli.HelpFlag) + cli.HelpFlag = stubFlag{} + + testhelper.Run(m) +} diff --git a/internal/featureflag/context.go b/internal/featureflag/context.go index caa0f0e48..58ca68782 100644 --- a/internal/featureflag/context.go +++ b/internal/featureflag/context.go @@ -1,4 +1,4 @@ -package featureflag +package featureflag //nolint:gitaly-linters // Importing testhelper creates a cyclic dependency. import ( "context" diff --git a/internal/git/conflict/testhelper_test.go b/internal/git/conflict/testhelper_test.go new file mode 100644 index 000000000..2de131e4b --- /dev/null +++ b/internal/git/conflict/testhelper_test.go @@ -0,0 +1,11 @@ +package conflict + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/git/gitio/testhelper_test.go b/internal/git/gitio/testhelper_test.go new file mode 100644 index 000000000..39575eb47 --- /dev/null +++ b/internal/git/gitio/testhelper_test.go @@ -0,0 +1,11 @@ +package gitio + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/git/pktline/testhelper_test.go b/internal/git/pktline/testhelper_test.go new file mode 100644 index 000000000..528293c8c --- /dev/null +++ b/internal/git/pktline/testhelper_test.go @@ -0,0 +1,11 @@ +package pktline + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/git/rawdiff/testhelper_test.go b/internal/git/rawdiff/testhelper_test.go new file mode 100644 index 000000000..f52f567c2 --- /dev/null +++ b/internal/git/rawdiff/testhelper_test.go @@ -0,0 +1,11 @@ +package rawdiff + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/git/smudge/testhelper_test.go b/internal/git/smudge/testhelper_test.go new file mode 100644 index 000000000..b19dd75b5 --- /dev/null +++ b/internal/git/smudge/testhelper_test.go @@ -0,0 +1,11 @@ +package smudge + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/git/trace2/testhelper_test.go b/internal/git/trace2/testhelper_test.go new file mode 100644 index 000000000..4500d7404 --- /dev/null +++ b/internal/git/trace2/testhelper_test.go @@ -0,0 +1,11 @@ +package trace2 + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/git/trace2hooks/packobjects_metrics_ext_test.go b/internal/git/trace2hooks/packobjects_metrics_ext_test.go index bdf29eb36..ee6ac89ad 100644 --- a/internal/git/trace2hooks/packobjects_metrics_ext_test.go +++ b/internal/git/trace2hooks/packobjects_metrics_ext_test.go @@ -19,10 +19,6 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" ) -func TestMain(m *testing.M) { - testhelper.Run(m) -} - func TestPackObjectsMetrics(t *testing.T) { t.Parallel() diff --git a/internal/git/trace2hooks/testhelper_test.go b/internal/git/trace2hooks/testhelper_test.go new file mode 100644 index 000000000..772af3543 --- /dev/null +++ b/internal/git/trace2hooks/testhelper_test.go @@ -0,0 +1,11 @@ +package trace2hooks + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/git/trailerparser/testhelper_test.go b/internal/git/trailerparser/testhelper_test.go new file mode 100644 index 000000000..b26271c1a --- /dev/null +++ b/internal/git/trailerparser/testhelper_test.go @@ -0,0 +1,11 @@ +package trailerparser + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/git/updateref/testhelper_test.go b/internal/git/updateref/testhelper_test.go new file mode 100644 index 000000000..bd3c3117a --- /dev/null +++ b/internal/git/updateref/testhelper_test.go @@ -0,0 +1,11 @@ +package updateref + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/git/updateref/updateref_test.go b/internal/git/updateref/updateref_test.go index 869e7f04b..d542c992c 100644 --- a/internal/git/updateref/updateref_test.go +++ b/internal/git/updateref/updateref_test.go @@ -21,10 +21,6 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testcfg" ) -func TestMain(m *testing.M) { - testhelper.Run(m) -} - func setupUpdater(tb testing.TB, ctx context.Context) (config.Cfg, *localrepo.Repo, string, *Updater) { tb.Helper() diff --git a/internal/gitaly/config/cgroups/testhelper_test.go b/internal/gitaly/config/cgroups/testhelper_test.go new file mode 100644 index 000000000..2eabe6510 --- /dev/null +++ b/internal/gitaly/config/cgroups/testhelper_test.go @@ -0,0 +1,11 @@ +package cgroups + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/gitaly/config/prometheus/testhelper_test.go b/internal/gitaly/config/prometheus/testhelper_test.go new file mode 100644 index 000000000..9653a830e --- /dev/null +++ b/internal/gitaly/config/prometheus/testhelper_test.go @@ -0,0 +1,11 @@ +package prometheus + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/gitaly/diff/testhelper_test.go b/internal/gitaly/diff/testhelper_test.go new file mode 100644 index 000000000..053cf6df0 --- /dev/null +++ b/internal/gitaly/diff/testhelper_test.go @@ -0,0 +1,11 @@ +package diff + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/gitaly/linguist/linguist_test.go b/internal/gitaly/linguist/linguist_test.go index c70b2a790..222173496 100644 --- a/internal/gitaly/linguist/linguist_test.go +++ b/internal/gitaly/linguist/linguist_test.go @@ -20,10 +20,6 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" ) -func TestMain(m *testing.M) { - testhelper.Run(m) -} - func TestInstance_Stats(t *testing.T) { t.Parallel() diff --git a/internal/gitaly/linguist/testhelper_test.go b/internal/gitaly/linguist/testhelper_test.go new file mode 100644 index 000000000..199d589a3 --- /dev/null +++ b/internal/gitaly/linguist/testhelper_test.go @@ -0,0 +1,11 @@ +package linguist + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/gitaly/maintenance/main_test.go b/internal/gitaly/maintenance/testhelper_test.go index c6832ae05..c6832ae05 100644 --- a/internal/gitaly/maintenance/main_test.go +++ b/internal/gitaly/maintenance/testhelper_test.go diff --git a/internal/gitaly/server/auth_test.go b/internal/gitaly/server/auth_test.go index 385a494d2..a30599de9 100644 --- a/internal/gitaly/server/auth_test.go +++ b/internal/gitaly/server/auth_test.go @@ -39,10 +39,6 @@ import ( healthpb "google.golang.org/grpc/health/grpc_health_v1" ) -func TestMain(m *testing.M) { - testhelper.Run(m) -} - func TestSanity(t *testing.T) { serverSocketPath := runServer(t, testcfg.Build(t)) diff --git a/internal/gitaly/service/server/server_test.go b/internal/gitaly/server/testhelper_test.go index 7846a01f9..7846a01f9 100644 --- a/internal/gitaly/service/server/server_test.go +++ b/internal/gitaly/server/testhelper_test.go diff --git a/internal/gitaly/service/namespace/namespace_test.go b/internal/gitaly/service/namespace/namespace_test.go index a77eecfa7..d49b78fcf 100644 --- a/internal/gitaly/service/namespace/namespace_test.go +++ b/internal/gitaly/service/namespace/namespace_test.go @@ -15,10 +15,6 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" ) -func TestMain(m *testing.M) { - testhelper.Run(m) -} - func TestNamespaceExists(t *testing.T) { cfg, client := setupNamespaceService(t, testserver.WithDisablePraefect()) existingStorage := cfg.Storages[0] diff --git a/internal/gitaly/service/namespace/testhelper_test.go b/internal/gitaly/service/namespace/testhelper_test.go index 7d5db0e07..2d8bd9bb4 100644 --- a/internal/gitaly/service/namespace/testhelper_test.go +++ b/internal/gitaly/service/namespace/testhelper_test.go @@ -14,6 +14,10 @@ import ( "google.golang.org/grpc/credentials/insecure" ) +func TestMain(m *testing.M) { + testhelper.Run(m) +} + func setupNamespaceService(tb testing.TB, opts ...testserver.GitalyServerOpt) (config.Cfg, gitalypb.NamespaceServiceClient) { cfgBuilder := testcfg.NewGitalyCfgBuilder(testcfg.WithStorages("default", "other")) cfg := cfgBuilder.Build(tb) diff --git a/internal/gitaly/service/server/testhelper_test.go b/internal/gitaly/service/server/testhelper_test.go new file mode 100644 index 000000000..7846a01f9 --- /dev/null +++ b/internal/gitaly/service/server/testhelper_test.go @@ -0,0 +1,11 @@ +package server + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/gitlab/client/testhelper_test.go b/internal/gitlab/client/testhelper_test.go new file mode 100644 index 000000000..137104d4d --- /dev/null +++ b/internal/gitlab/client/testhelper_test.go @@ -0,0 +1,11 @@ +package client + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/backchannel/testhelper_test.go b/internal/grpc/backchannel/testhelper_test.go new file mode 100644 index 000000000..c2ba27cbb --- /dev/null +++ b/internal/grpc/backchannel/testhelper_test.go @@ -0,0 +1,11 @@ +package backchannel + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/client/testhelper_test.go b/internal/grpc/client/testhelper_test.go new file mode 100644 index 000000000..137104d4d --- /dev/null +++ b/internal/grpc/client/testhelper_test.go @@ -0,0 +1,11 @@ +package client + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/grpcstats/testhelper_test.go b/internal/grpc/grpcstats/testhelper_test.go index f57175b92..d0b298d5f 100644 --- a/internal/grpc/grpcstats/testhelper_test.go +++ b/internal/grpc/grpcstats/testhelper_test.go @@ -1,4 +1,4 @@ -package grpcstats_test +package grpcstats import ( "testing" diff --git a/internal/grpc/listenmux/testhelper_test.go b/internal/grpc/listenmux/testhelper_test.go new file mode 100644 index 000000000..3cd68209c --- /dev/null +++ b/internal/grpc/listenmux/testhelper_test.go @@ -0,0 +1,11 @@ +package listenmux + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/metadata/testhelper_test.go b/internal/grpc/metadata/testhelper_test.go new file mode 100644 index 000000000..bfb393903 --- /dev/null +++ b/internal/grpc/metadata/testhelper_test.go @@ -0,0 +1,11 @@ +package metadata + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/middleware/cache/cache_test.go b/internal/grpc/middleware/cache/cache_test.go index e9b924d09..02b2fa603 100644 --- a/internal/grpc/middleware/cache/cache_test.go +++ b/internal/grpc/middleware/cache/cache_test.go @@ -137,6 +137,7 @@ func TestInvalidators(t *testing.T) { grpc.WithTransportCredentials(insecure.NewCredentials()), ) require.NoError(t, err) + defer testhelper.MustClose(t, conn) tc.invokeRPC(t, conn) diff --git a/internal/grpc/middleware/cache/testhelper_test.go b/internal/grpc/middleware/cache/testhelper_test.go new file mode 100644 index 000000000..6c55da37a --- /dev/null +++ b/internal/grpc/middleware/cache/testhelper_test.go @@ -0,0 +1,11 @@ +package cache + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/middleware/customfieldshandler/customfields_handler_test.go b/internal/grpc/middleware/customfieldshandler/customfields_handler_test.go index 67568378b..60adabe47 100644 --- a/internal/grpc/middleware/customfieldshandler/customfields_handler_test.go +++ b/internal/grpc/middleware/customfieldshandler/customfields_handler_test.go @@ -25,10 +25,6 @@ import ( "google.golang.org/grpc/test/bufconn" ) -func TestMain(m *testing.M) { - testhelper.Run(m) -} - func createNewServer(t *testing.T, cfg config.Cfg, logger *logrus.Logger) *grpc.Server { t.Helper() diff --git a/internal/grpc/middleware/customfieldshandler/testhelper_test.go b/internal/grpc/middleware/customfieldshandler/testhelper_test.go new file mode 100644 index 000000000..16e038e4e --- /dev/null +++ b/internal/grpc/middleware/customfieldshandler/testhelper_test.go @@ -0,0 +1,11 @@ +package customfieldshandler + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/middleware/featureflag/testhelper_test.go b/internal/grpc/middleware/featureflag/testhelper_test.go new file mode 100644 index 000000000..3b7d11638 --- /dev/null +++ b/internal/grpc/middleware/featureflag/testhelper_test.go @@ -0,0 +1,11 @@ +package featureflag + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/middleware/metadatahandler/testhelper_test.go b/internal/grpc/middleware/metadatahandler/testhelper_test.go new file mode 100644 index 000000000..ee8340678 --- /dev/null +++ b/internal/grpc/middleware/metadatahandler/testhelper_test.go @@ -0,0 +1,11 @@ +package metadatahandler + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/middleware/sentryhandler/testhelper_test.go b/internal/grpc/middleware/sentryhandler/testhelper_test.go new file mode 100644 index 000000000..d9287d14e --- /dev/null +++ b/internal/grpc/middleware/sentryhandler/testhelper_test.go @@ -0,0 +1,11 @@ +package sentryhandler + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/middleware/statushandler/testhelper_test.go b/internal/grpc/middleware/statushandler/testhelper_test.go new file mode 100644 index 000000000..3437d6df2 --- /dev/null +++ b/internal/grpc/middleware/statushandler/testhelper_test.go @@ -0,0 +1,11 @@ +package statushandler + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/protoregistry/testhelper_test.go b/internal/grpc/protoregistry/testhelper_test.go new file mode 100644 index 000000000..07f146a30 --- /dev/null +++ b/internal/grpc/protoregistry/testhelper_test.go @@ -0,0 +1,11 @@ +package protoregistry + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/grpc/proxy/proxy_test_testhelper_test.go b/internal/grpc/proxy/proxy_test_testhelper_test.go new file mode 100644 index 000000000..2c3493743 --- /dev/null +++ b/internal/grpc/proxy/proxy_test_testhelper_test.go @@ -0,0 +1,121 @@ +package proxy_test + +import ( + "context" + "net" + "testing" + + grpcmwtags "github.com/grpc-ecosystem/go-grpc-middleware/tags" + "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/v16/internal/grpc/middleware/sentryhandler" + "gitlab.com/gitlab-org/gitaly/v16/internal/grpc/proxy" + "gitlab.com/gitlab-org/gitaly/v16/internal/helper/fieldextractors" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/interop/grpc_testing" +) + +func newListener(tb testing.TB) net.Listener { + listener, err := net.Listen("tcp", "127.0.0.1:0") + require.NoError(tb, err, "must be able to allocate a port for listener") + + return listener +} + +func newBackendPinger(tb testing.TB, ctx context.Context) (*grpc.ClientConn, *interceptPinger) { + ip := &interceptPinger{} + + srvr := grpc.NewServer() + listener := newListener(tb) + + grpc_testing.RegisterTestServiceServer(srvr, ip) + + done := make(chan struct{}) + go func() { + defer close(done) + require.NoError(tb, srvr.Serve(listener)) + }() + + cc, err := grpc.DialContext( + ctx, + listener.Addr().String(), + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithBlock(), + grpc.WithDefaultCallOptions( + grpc.ForceCodec(proxy.NewCodec()), + ), + ) + require.NoError(tb, err) + + tb.Cleanup(func() { + srvr.GracefulStop() + require.NoError(tb, cc.Close()) + <-done + }) + + return cc, ip +} + +func newProxy(tb testing.TB, ctx context.Context, director proxy.StreamDirector, svc, method string) *grpc.ClientConn { + proxySrvr := grpc.NewServer( + grpc.ForceServerCodec(proxy.NewCodec()), + grpc.ChainStreamInterceptor( + // context tags usage is required by sentryhandler.StreamLogHandler + grpcmwtags.StreamServerInterceptor(grpcmwtags.WithFieldExtractorForInitialReq(fieldextractors.FieldExtractor)), + // sentry middleware to capture errors + sentryhandler.StreamLogHandler, + ), + grpc.UnknownServiceHandler(proxy.TransparentHandler(director)), + ) + proxy.RegisterService(proxySrvr, director, svc, method) + + done := make(chan struct{}) + listener := newListener(tb) + go func() { + defer close(done) + require.NoError(tb, proxySrvr.Serve(listener)) + }() + + proxyCC, err := grpc.DialContext( + ctx, + listener.Addr().String(), + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithBlock(), + ) + require.NoError(tb, err) + + tb.Cleanup(func() { + proxySrvr.GracefulStop() + require.NoError(tb, proxyCC.Close()) + <-done + }) + + return proxyCC +} + +// interceptPinger allows an RPC to be intercepted with a custom +// function defined in each unit test +type interceptPinger struct { + grpc_testing.UnimplementedTestServiceServer + + fullDuplexCall func(grpc_testing.TestService_FullDuplexCallServer) error + emptyCall func(context.Context, *grpc_testing.Empty) (*grpc_testing.Empty, error) + unaryCall func(context.Context, *grpc_testing.SimpleRequest) (*grpc_testing.SimpleResponse, error) + streamingOutputCall func(*grpc_testing.StreamingOutputCallRequest, grpc_testing.TestService_StreamingOutputCallServer) error +} + +func (ip *interceptPinger) FullDuplexCall(stream grpc_testing.TestService_FullDuplexCallServer) error { + return ip.fullDuplexCall(stream) +} + +func (ip *interceptPinger) EmptyCall(ctx context.Context, req *grpc_testing.Empty) (*grpc_testing.Empty, error) { + return ip.emptyCall(ctx, req) +} + +func (ip *interceptPinger) UnaryCall(ctx context.Context, req *grpc_testing.SimpleRequest) (*grpc_testing.SimpleResponse, error) { + return ip.unaryCall(ctx, req) +} + +func (ip *interceptPinger) StreamingOutputCall(req *grpc_testing.StreamingOutputCallRequest, stream grpc_testing.TestService_StreamingOutputCallServer) error { + return ip.streamingOutputCall(req, stream) +} diff --git a/internal/grpc/proxy/testhelper_test.go b/internal/grpc/proxy/testhelper_test.go index 5efcfa265..458219da2 100644 --- a/internal/grpc/proxy/testhelper_test.go +++ b/internal/grpc/proxy/testhelper_test.go @@ -1,126 +1,11 @@ -package proxy_test +package proxy import ( - "context" - "net" "testing" - grpcmwtags "github.com/grpc-ecosystem/go-grpc-middleware/tags" - "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/v16/internal/grpc/middleware/sentryhandler" - "gitlab.com/gitlab-org/gitaly/v16/internal/grpc/proxy" - "gitlab.com/gitlab-org/gitaly/v16/internal/helper/fieldextractors" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" - "google.golang.org/grpc/interop/grpc_testing" ) func TestMain(m *testing.M) { testhelper.Run(m) } - -func newListener(tb testing.TB) net.Listener { - listener, err := net.Listen("tcp", "127.0.0.1:0") - require.NoError(tb, err, "must be able to allocate a port for listener") - - return listener -} - -func newBackendPinger(tb testing.TB, ctx context.Context) (*grpc.ClientConn, *interceptPinger) { - ip := &interceptPinger{} - - srvr := grpc.NewServer() - listener := newListener(tb) - - grpc_testing.RegisterTestServiceServer(srvr, ip) - - done := make(chan struct{}) - go func() { - defer close(done) - require.NoError(tb, srvr.Serve(listener)) - }() - - cc, err := grpc.DialContext( - ctx, - listener.Addr().String(), - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock(), - grpc.WithDefaultCallOptions( - grpc.ForceCodec(proxy.NewCodec()), - ), - ) - require.NoError(tb, err) - - tb.Cleanup(func() { - srvr.GracefulStop() - require.NoError(tb, cc.Close()) - <-done - }) - - return cc, ip -} - -func newProxy(tb testing.TB, ctx context.Context, director proxy.StreamDirector, svc, method string) *grpc.ClientConn { - proxySrvr := grpc.NewServer( - grpc.ForceServerCodec(proxy.NewCodec()), - grpc.ChainStreamInterceptor( - // context tags usage is required by sentryhandler.StreamLogHandler - grpcmwtags.StreamServerInterceptor(grpcmwtags.WithFieldExtractorForInitialReq(fieldextractors.FieldExtractor)), - // sentry middleware to capture errors - sentryhandler.StreamLogHandler, - ), - grpc.UnknownServiceHandler(proxy.TransparentHandler(director)), - ) - proxy.RegisterService(proxySrvr, director, svc, method) - - done := make(chan struct{}) - listener := newListener(tb) - go func() { - defer close(done) - require.NoError(tb, proxySrvr.Serve(listener)) - }() - - proxyCC, err := grpc.DialContext( - ctx, - listener.Addr().String(), - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock(), - ) - require.NoError(tb, err) - - tb.Cleanup(func() { - proxySrvr.GracefulStop() - require.NoError(tb, proxyCC.Close()) - <-done - }) - - return proxyCC -} - -// interceptPinger allows an RPC to be intercepted with a custom -// function defined in each unit test -type interceptPinger struct { - grpc_testing.UnimplementedTestServiceServer - - fullDuplexCall func(grpc_testing.TestService_FullDuplexCallServer) error - emptyCall func(context.Context, *grpc_testing.Empty) (*grpc_testing.Empty, error) - unaryCall func(context.Context, *grpc_testing.SimpleRequest) (*grpc_testing.SimpleResponse, error) - streamingOutputCall func(*grpc_testing.StreamingOutputCallRequest, grpc_testing.TestService_StreamingOutputCallServer) error -} - -func (ip *interceptPinger) FullDuplexCall(stream grpc_testing.TestService_FullDuplexCallServer) error { - return ip.fullDuplexCall(stream) -} - -func (ip *interceptPinger) EmptyCall(ctx context.Context, req *grpc_testing.Empty) (*grpc_testing.Empty, error) { - return ip.emptyCall(ctx, req) -} - -func (ip *interceptPinger) UnaryCall(ctx context.Context, req *grpc_testing.SimpleRequest) (*grpc_testing.SimpleResponse, error) { - return ip.unaryCall(ctx, req) -} - -func (ip *interceptPinger) StreamingOutputCall(req *grpc_testing.StreamingOutputCallRequest, stream grpc_testing.TestService_StreamingOutputCallServer) error { - return ip.streamingOutputCall(req, stream) -} diff --git a/internal/grpc/sidechannel/testhelper_test.go b/internal/grpc/sidechannel/testhelper_test.go new file mode 100644 index 000000000..746f17eba --- /dev/null +++ b/internal/grpc/sidechannel/testhelper_test.go @@ -0,0 +1,11 @@ +package sidechannel + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/helper/chunk/chunker_test.go b/internal/helper/chunk/chunker_test.go index 68a444bab..1eb1a1e36 100644 --- a/internal/helper/chunk/chunker_test.go +++ b/internal/helper/chunk/chunker_test.go @@ -14,10 +14,6 @@ import ( "google.golang.org/protobuf/proto" ) -func TestMain(m *testing.M) { - testhelper.Run(m) -} - type testSender struct { stream grpc_testing.TestService_StreamingOutputCallServer body []byte diff --git a/internal/helper/chunk/testhelper_test.go b/internal/helper/chunk/testhelper_test.go new file mode 100644 index 000000000..e81d92db6 --- /dev/null +++ b/internal/helper/chunk/testhelper_test.go @@ -0,0 +1,11 @@ +package chunk + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/helper/duration/testhelper_test.go b/internal/helper/duration/testhelper_test.go new file mode 100644 index 000000000..a0d9e8f7f --- /dev/null +++ b/internal/helper/duration/testhelper_test.go @@ -0,0 +1,11 @@ +package duration + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/helper/env/testhelper_test.go b/internal/helper/env/testhelper_test.go new file mode 100644 index 000000000..5fb46d8dc --- /dev/null +++ b/internal/helper/env/testhelper_test.go @@ -0,0 +1,11 @@ +package env_test + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/helper/fstype/testhelper_test.go b/internal/helper/fstype/testhelper_test.go new file mode 100644 index 000000000..10ba5c1a8 --- /dev/null +++ b/internal/helper/fstype/testhelper_test.go @@ -0,0 +1,11 @@ +package fstype + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/helper/lines/testhelper_test.go b/internal/helper/lines/testhelper_test.go new file mode 100644 index 000000000..c1230a761 --- /dev/null +++ b/internal/helper/lines/testhelper_test.go @@ -0,0 +1,11 @@ +package lines + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/helper/perm/perm_test.go b/internal/helper/perm/perm_test.go index 39ee78625..283d768ff 100644 --- a/internal/helper/perm/perm_test.go +++ b/internal/helper/perm/perm_test.go @@ -1,4 +1,4 @@ -package perm +package perm_test import ( "io/fs" @@ -6,13 +6,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/v16/internal/helper/perm" ) func TestUmaskMask(t *testing.T) { for _, tc := range []struct { desc string mode fs.FileMode - umask Umask + umask perm.Umask expectedMode fs.FileMode }{ { diff --git a/internal/helper/perm/testhelper_test.go b/internal/helper/perm/testhelper_test.go new file mode 100644 index 000000000..011814ee8 --- /dev/null +++ b/internal/helper/perm/testhelper_test.go @@ -0,0 +1,11 @@ +package perm_test + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/helper/testhelper_test.go b/internal/helper/testhelper_test.go new file mode 100644 index 000000000..c57af0dad --- /dev/null +++ b/internal/helper/testhelper_test.go @@ -0,0 +1,11 @@ +package helper + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/helper/text/chomp_test.go b/internal/helper/text/chomp_test.go index fbdb1ecbc..5d707bbeb 100644 --- a/internal/helper/text/chomp_test.go +++ b/internal/helper/text/chomp_test.go @@ -1,9 +1,10 @@ -package text +package text_test import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/v16/internal/helper/text" ) func TestChompBytes(t *testing.T) { @@ -23,7 +24,7 @@ func TestChompBytes(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - require.Equal(t, tc.out, ChompBytes(tc.in)) + require.Equal(t, tc.out, text.ChompBytes(tc.in)) }) } } diff --git a/internal/helper/text/testhelper_test.go b/internal/helper/text/testhelper_test.go new file mode 100644 index 000000000..6483830f2 --- /dev/null +++ b/internal/helper/text/testhelper_test.go @@ -0,0 +1,11 @@ +package text_test + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/limiter/testhelper_test.go b/internal/limiter/testhelper_test.go new file mode 100644 index 000000000..419ba2158 --- /dev/null +++ b/internal/limiter/testhelper_test.go @@ -0,0 +1,11 @@ +package limiter + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/limiter/watchers/testhelper_test.go b/internal/limiter/watchers/testhelper_test.go index 39cb89546..fa9539a20 100644 --- a/internal/limiter/watchers/testhelper_test.go +++ b/internal/limiter/watchers/testhelper_test.go @@ -2,9 +2,11 @@ package watchers import ( "os/exec" + "testing" "github.com/prometheus/client_golang/prometheus" "gitlab.com/gitlab-org/gitaly/v16/internal/cgroups" + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" ) type testCgroupManager struct { @@ -14,6 +16,10 @@ type testCgroupManager struct { statsIndex int } +func TestMain(m *testing.M) { + testhelper.Run(m) +} + func (m *testCgroupManager) Ready() bool { return m.ready } func (m *testCgroupManager) Stats() (cgroups.Stats, error) { m.statsIndex++ diff --git a/internal/log/customfields.go b/internal/log/customfields.go index 38874e15c..64bb59566 100644 --- a/internal/log/customfields.go +++ b/internal/log/customfields.go @@ -1,4 +1,4 @@ -package log +package log //nolint:gitaly-linters // Importing testhelper creates a cyclic dependency. import ( "context" diff --git a/internal/praefect/metrics/testhelper_test.go b/internal/praefect/metrics/testhelper_test.go new file mode 100644 index 000000000..843d467d4 --- /dev/null +++ b/internal/praefect/metrics/testhelper_test.go @@ -0,0 +1,11 @@ +package metrics + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/praefect/middleware/helper_test.go b/internal/praefect/middleware/testhelper_test.go index 06fab764a..06fab764a 100644 --- a/internal/praefect/middleware/helper_test.go +++ b/internal/praefect/middleware/testhelper_test.go diff --git a/internal/praefect/nodes/init_test.go b/internal/praefect/nodes/testhelper_test.go index 74decdf85..74decdf85 100644 --- a/internal/praefect/nodes/init_test.go +++ b/internal/praefect/nodes/testhelper_test.go diff --git a/internal/praefect/nodes/tracker/testhelper_test.go b/internal/praefect/nodes/tracker/testhelper_test.go new file mode 100644 index 000000000..aabde6553 --- /dev/null +++ b/internal/praefect/nodes/tracker/testhelper_test.go @@ -0,0 +1,11 @@ +package tracker + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/praefect/reconciler/testhelper_test.go b/internal/praefect/reconciler/testhelper_test.go new file mode 100644 index 000000000..d489e2e02 --- /dev/null +++ b/internal/praefect/reconciler/testhelper_test.go @@ -0,0 +1,11 @@ +package reconciler + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/praefect/repocleaner/init_test.go b/internal/praefect/repocleaner/testhelper_test.go index ce0132551..ce0132551 100644 --- a/internal/praefect/repocleaner/init_test.go +++ b/internal/praefect/repocleaner/testhelper_test.go diff --git a/internal/praefect/service/helper_test.go b/internal/praefect/service/testhelper_test.go index 084c50d6c..084c50d6c 100644 --- a/internal/praefect/service/helper_test.go +++ b/internal/praefect/service/testhelper_test.go diff --git a/internal/praefect/transactions/testhelper_test.go b/internal/praefect/transactions/testhelper_test.go new file mode 100644 index 000000000..cdc7934b9 --- /dev/null +++ b/internal/praefect/transactions/testhelper_test.go @@ -0,0 +1,11 @@ +package transactions + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/ps/testhelper_test.go b/internal/ps/testhelper_test.go new file mode 100644 index 000000000..86cb86e6d --- /dev/null +++ b/internal/ps/testhelper_test.go @@ -0,0 +1,11 @@ +package ps + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/safe/testhelper_test.go b/internal/safe/testhelper_test.go new file mode 100644 index 000000000..56f4b4002 --- /dev/null +++ b/internal/safe/testhelper_test.go @@ -0,0 +1,11 @@ +package safe + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/signature/testhelper_test.go b/internal/signature/testhelper_test.go new file mode 100644 index 000000000..52b02e6da --- /dev/null +++ b/internal/signature/testhelper_test.go @@ -0,0 +1,11 @@ +package signature + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/structerr/error.go b/internal/structerr/error.go index 048258b6b..4b88f2c16 100644 --- a/internal/structerr/error.go +++ b/internal/structerr/error.go @@ -1,4 +1,4 @@ -package structerr +package structerr //nolint:gitaly-linters // Importing testhelper creates a cyclic dependency. import ( "errors" diff --git a/internal/testhelper/testdb/testhelper_test.go b/internal/testhelper/testdb/testhelper_test.go new file mode 100644 index 000000000..124932072 --- /dev/null +++ b/internal/testhelper/testdb/testhelper_test.go @@ -0,0 +1,11 @@ +package testdb + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/testhelper/testhelper_test.go b/internal/testhelper/testhelper_test.go new file mode 100644 index 000000000..a91779dd4 --- /dev/null +++ b/internal/testhelper/testhelper_test.go @@ -0,0 +1,9 @@ +package testhelper + +import ( + "testing" +) + +func TestMain(m *testing.M) { + Run(m) +} diff --git a/internal/testhelper/testserver/testhelper_test.go b/internal/testhelper/testserver/testhelper_test.go new file mode 100644 index 000000000..d09ca3b54 --- /dev/null +++ b/internal/testhelper/testserver/testhelper_test.go @@ -0,0 +1,11 @@ +package testserver + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} diff --git a/internal/tracing/passthrough_test.go b/internal/tracing/passthrough_test.go index 5d52fb770..31bd3a50f 100644 --- a/internal/tracing/passthrough_test.go +++ b/internal/tracing/passthrough_test.go @@ -279,6 +279,7 @@ func startFakeGitalyServer(t *testing.T, svc *testSvc, spanContext opentracing.S grpc.WithStreamInterceptor(StreamPassthroughInterceptor(spanContext)), ) require.NoError(t, err) + t.Cleanup(func() { testhelper.MustClose(t, conn) }) return grpc_testing.NewTestServiceClient(conn) } diff --git a/internal/tracing/testhelper_test.go b/internal/tracing/testhelper_test.go new file mode 100644 index 000000000..f940df2d1 --- /dev/null +++ b/internal/tracing/testhelper_test.go @@ -0,0 +1,11 @@ +package tracing + +import ( + "testing" + + "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" +) + +func TestMain(m *testing.M) { + testhelper.Run(m) +} |