diff options
13 files changed, 78 insertions, 66 deletions
diff --git a/internal/git/localrepo/remote_extra_test.go b/internal/git/localrepo/remote_extra_test.go index fe2027d24..6e9e523a2 100644 --- a/internal/git/localrepo/remote_extra_test.go +++ b/internal/git/localrepo/remote_extra_test.go @@ -55,7 +55,7 @@ func TestRepo_FetchInternal(t *testing.T) { require.NoError(t, err) t.Run("refspec with tag", func(t *testing.T) { - ctx := testhelper.MergeIncomingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx := testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -84,7 +84,7 @@ func TestRepo_FetchInternal(t *testing.T) { }) t.Run("refspec without tags", func(t *testing.T) { - ctx := testhelper.MergeIncomingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx := testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -104,7 +104,7 @@ func TestRepo_FetchInternal(t *testing.T) { }) t.Run("object ID", func(t *testing.T) { - ctx := testhelper.MergeIncomingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx := testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -120,7 +120,7 @@ func TestRepo_FetchInternal(t *testing.T) { }) t.Run("nonexistent revision", func(t *testing.T) { - ctx := testhelper.MergeIncomingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx := testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -136,7 +136,7 @@ func TestRepo_FetchInternal(t *testing.T) { }) t.Run("with env", func(t *testing.T) { - ctx := testhelper.MergeIncomingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx := testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -151,7 +151,7 @@ func TestRepo_FetchInternal(t *testing.T) { }) t.Run("with disabled transactions", func(t *testing.T) { - ctx := testhelper.MergeIncomingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx := testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -166,7 +166,7 @@ func TestRepo_FetchInternal(t *testing.T) { }) t.Run("invalid remote repo", func(t *testing.T) { - ctx := testhelper.MergeIncomingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx := testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -181,7 +181,7 @@ func TestRepo_FetchInternal(t *testing.T) { }) t.Run("pruning", func(t *testing.T) { - ctx := testhelper.MergeIncomingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx := testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) repo := localrepo.NewTestRepo(t, cfg, repoProto) diff --git a/internal/gitaly/service/conflicts/resolve_conflicts_test.go b/internal/gitaly/service/conflicts/resolve_conflicts_test.go index 9bc790d89..3b15de756 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts_test.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts_test.go @@ -20,6 +20,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/hook" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -141,7 +142,7 @@ func TestSuccessfulResolveConflictsRequestHelper(t *testing.T) { hookManager := hook.NewMockManager(t, verifyFunc, verifyFunc, hook.NopUpdate, hook.NopReferenceTransaction) client := SetupConflictsServiceWithConfig(t, &cfg, hookManager) - mdGS := testhelper.GitalyServersMetadataFromCfg(t, cfg) + mdGS := testcfg.GitalyServersMetadataFromCfg(t, cfg) mdFF, _ := metadata.FromOutgoingContext(ctx) ctx = metadata.NewOutgoingContext(ctx, metadata.Join(mdGS, mdFF)) @@ -219,7 +220,7 @@ func TestResolveConflictsWithRemoteRepo(t *testing.T) { ) gittest.Exec(t, cfg, "-C", targetRepoPath, "update-ref", "refs/heads/target", targetCommitOID.String()) - ctx = testhelper.MergeOutgoingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) stream, err := client.ResolveConflicts(ctx) require.NoError(t, err) @@ -268,7 +269,7 @@ func TestResolveConflictsLineEndings(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - ctx = testhelper.MergeOutgoingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) for _, tc := range []struct { desc string @@ -389,7 +390,7 @@ func TestResolveConflictsNonOIDRequests(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - ctx = testhelper.MergeOutgoingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) stream, err := client.ResolveConflicts(ctx) require.NoError(t, err) @@ -488,7 +489,7 @@ func TestResolveConflictsIdenticalContent(t *testing.T) { }) require.NoError(t, err) - ctx = testhelper.MergeOutgoingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) stream, err := client.ResolveConflicts(ctx) require.NoError(t, err) @@ -527,7 +528,7 @@ func TestResolveConflictsStableID(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - md := testhelper.GitalyServersMetadataFromCfg(t, cfg) + md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx = testhelper.MergeOutgoingMetadata(ctx, md) stream, err := client.ResolveConflicts(ctx) @@ -594,7 +595,7 @@ func TestFailedResolveConflictsRequestDueToResolutionError(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - mdGS := testhelper.GitalyServersMetadataFromCfg(t, cfg) + mdGS := testcfg.GitalyServersMetadataFromCfg(t, cfg) mdFF, _ := metadata.FromOutgoingContext(ctx) ctx = metadata.NewOutgoingContext(ctx, metadata.Join(mdGS, mdFF)) @@ -652,7 +653,7 @@ func TestFailedResolveConflictsRequestDueToValidation(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - mdGS := testhelper.GitalyServersMetadataFromCfg(t, cfg) + mdGS := testcfg.GitalyServersMetadataFromCfg(t, cfg) ourCommitOid := "1450cd639e0bc6721eb02800169e464f212cde06" theirCommitOid := "824be604a34828eb682305f0d963056cfac87b2d" commitMsg := []byte(conflictResolutionCommitMessage) @@ -845,7 +846,7 @@ func TestResolveConflictsQuarantine(t *testing.T) { ) gittest.Exec(t, cfg, "-C", targetRepoPath, "update-ref", "refs/heads/target", targetCommitOID.String()) - ctx = testhelper.MergeOutgoingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) stream, err := client.ResolveConflicts(ctx) require.NoError(t, err) diff --git a/internal/gitaly/service/operations/commit_files_test.go b/internal/gitaly/service/operations/commit_files_test.go index 5f78369c1..b98bf070f 100644 --- a/internal/gitaly/service/operations/commit_files_test.go +++ b/internal/gitaly/service/operations/commit_files_test.go @@ -18,6 +18,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -950,7 +951,7 @@ func TestUserCommitFilesStableCommitID(t *testing.T) { repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) repo := localrepo.NewTestRepo(t, cfg, repoProto) - for key, values := range testhelper.GitalyServersMetadataFromCfg(t, cfg) { + for key, values := range testcfg.GitalyServersMetadataFromCfg(t, cfg) { for _, value := range values { ctx = metadata.AppendToOutgoingContext(ctx, key, value) } @@ -1010,7 +1011,7 @@ func TestUserCommitFilesQuarantine(t *testing.T) { repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) repo := localrepo.NewTestRepo(t, cfg, repoProto) - ctx = testhelper.MergeOutgoingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) outputPath := filepath.Join(testhelper.TempDir(t), "output") diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go index 2987d42ee..dc6613c19 100644 --- a/internal/gitaly/service/operations/testhelper_test.go +++ b/internal/gitaly/service/operations/testhelper_test.go @@ -56,7 +56,7 @@ func setupOperationsServiceWithCfg( client, conn := newOperationClient(t, serverSocketPath) t.Cleanup(func() { conn.Close() }) - md := testhelper.GitalyServersMetadataFromCfg(t, cfg) + md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx = testhelper.MergeOutgoingMetadata(ctx, md) return ctx, cfg, repo, repoPath, client diff --git a/internal/gitaly/service/remote/fetch_internal_remote_test.go b/internal/gitaly/service/remote/fetch_internal_remote_test.go index e9839647d..96cb88ca2 100644 --- a/internal/gitaly/service/remote/fetch_internal_remote_test.go +++ b/internal/gitaly/service/remote/fetch_internal_remote_test.go @@ -171,7 +171,7 @@ func TestFetchInternalRemote_failure(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - ctx = testhelper.MergeIncomingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) connsPool := client.NewPool() defer connsPool.Close() diff --git a/internal/gitaly/service/repository/clone_from_pool_internal_test.go b/internal/gitaly/service/repository/clone_from_pool_internal_test.go index 72f17d230..c278c2a3f 100644 --- a/internal/gitaly/service/repository/clone_from_pool_internal_test.go +++ b/internal/gitaly/service/repository/clone_from_pool_internal_test.go @@ -16,6 +16,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/metadata" ) @@ -61,7 +62,7 @@ func TestCloneFromPoolInternal(t *testing.T) { ctxOuter, cancel := testhelper.Context() defer cancel() - md := testhelper.GitalyServersMetadataFromCfg(t, cfg) + md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx := metadata.NewOutgoingContext(ctxOuter, md) pool, poolRepo := newTestObjectPool(t, cfg) diff --git a/internal/gitaly/service/repository/clone_from_pool_test.go b/internal/gitaly/service/repository/clone_from_pool_test.go index 41de34186..457e22700 100644 --- a/internal/gitaly/service/repository/clone_from_pool_test.go +++ b/internal/gitaly/service/repository/clone_from_pool_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/metadata" ) @@ -18,7 +19,7 @@ func TestCloneFromPoolHTTP(t *testing.T) { ctxOuter, cancel := testhelper.Context() defer cancel() - md := testhelper.GitalyServersMetadataFromCfg(t, cfg) + md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx := metadata.NewOutgoingContext(ctxOuter, md) pool, poolRepo := newTestObjectPool(t, cfg) diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go index 5ac9fb2b6..0bcca1290 100644 --- a/internal/gitaly/service/repository/fetch_test.go +++ b/internal/gitaly/service/repository/fetch_test.go @@ -8,6 +8,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -19,7 +20,7 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - md := testhelper.GitalyServersMetadataFromCfg(t, cfg) + md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx = testhelper.MergeOutgoingMetadata(ctx, md) targetRepoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) @@ -52,7 +53,7 @@ func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - md := testhelper.GitalyServersMetadataFromCfg(t, cfg) + md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx = testhelper.MergeOutgoingMetadata(ctx, md) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -84,7 +85,7 @@ func TestFetchSourceBranchBranchNotFound(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - md := testhelper.GitalyServersMetadataFromCfg(t, cfg) + md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx = testhelper.MergeOutgoingMetadata(ctx, md) sourceRepo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) @@ -132,7 +133,7 @@ func TestFetchSourceBranchWrongRef(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - md := testhelper.GitalyServersMetadataFromCfg(t, cfg) + md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx = testhelper.MergeOutgoingMetadata(ctx, md) sourceRepo, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) diff --git a/internal/gitaly/service/repository/fork_test.go b/internal/gitaly/service/repository/fork_test.go index 092ec2e07..c1ffae9ad 100644 --- a/internal/gitaly/service/repository/fork_test.go +++ b/internal/gitaly/service/repository/fork_test.go @@ -82,7 +82,7 @@ func TestSuccessfulCreateForkRequest(t *testing.T) { ctxOuter, cancel := testhelper.Context() defer cancel() - md := testhelper.GitalyServersMetadataFromCfg(t, cfg) + md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx := metadata.NewOutgoingContext(ctxOuter, md) forkedRepo := &gitalypb.Repository{ @@ -142,7 +142,7 @@ func TestFailedCreateForkRequestDueToExistingTarget(t *testing.T) { ctxOuter, cancel := testhelper.Context() defer cancel() - md := testhelper.GitalyServersMetadataFromCfg(t, cfg) + md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx := metadata.NewOutgoingContext(ctxOuter, md) testCases := []struct { diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go index d410652ef..f8fa705b8 100644 --- a/internal/gitaly/service/repository/replicate_test.go +++ b/internal/gitaly/service/repository/replicate_test.go @@ -60,7 +60,7 @@ func TestReplicateRepository(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - ctx = testhelper.MergeOutgoingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) _, err = client.ReplicateRepository(ctx, &gitalypb.ReplicateRepositoryRequest{ Repository: targetRepo, @@ -128,7 +128,7 @@ func TestReplicateRepositoryTransactional(t *testing.T) { ctx, err := txinfo.InjectTransaction(ctx, 1, "primary", true) require.NoError(t, err) ctx = metadata.IncomingToOutgoing(ctx) - ctx = testhelper.MergeOutgoingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) client := newMuxedRepositoryClient(t, ctx, cfg, serverSocketPath, backchannel.NewClientHandshaker( testhelper.DiscardTestEntry(t), @@ -315,7 +315,7 @@ func TestReplicateRepository_BadRepository(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - ctx = testhelper.MergeOutgoingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) _, err := client.ReplicateRepository(ctx, &gitalypb.ReplicateRepositoryRequest{ Repository: targetRepo, @@ -361,7 +361,7 @@ func TestReplicateRepository_FailedFetchInternalRemote(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - ctx = testhelper.MergeOutgoingMetadata(ctx, testhelper.GitalyServersMetadataFromCfg(t, cfg)) + ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) repoClient := newRepositoryClient(t, cfg, cfg.SocketPath) diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go index fdc2e4685..bb31f2ac8 100644 --- a/internal/praefect/replicator_test.go +++ b/internal/praefect/replicator_test.go @@ -103,7 +103,7 @@ func TestReplMgr_ProcessBacklog(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - injectedCtx := metadata.NewOutgoingContext(ctx, testhelper.GitalyServersMetadataFromCfg(t, primaryCfg)) + injectedCtx := metadata.NewOutgoingContext(ctx, testcfg.GitalyServersMetadataFromCfg(t, primaryCfg)) repoClient := newRepositoryClient(t, backupCfg.SocketPath, backupCfg.Auth.Token) _, err = repoClient.ReplicateRepository(injectedCtx, &gitalypb.ReplicateRepositoryRequest{ diff --git a/internal/testhelper/testcfg/metadata.go b/internal/testhelper/testcfg/metadata.go new file mode 100644 index 000000000..df4cb274a --- /dev/null +++ b/internal/testhelper/testcfg/metadata.go @@ -0,0 +1,39 @@ +package testcfg + +import ( + "encoding/base64" + "encoding/json" + "testing" + + "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config" + "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/storage" + "google.golang.org/grpc/metadata" +) + +// GitalyServersMetadataFromCfg returns a metadata pair for gitaly-servers to be used in +// inter-gitaly operations. +func GitalyServersMetadataFromCfg(t testing.TB, cfg config.Cfg) metadata.MD { + gitalyServers := storage.GitalyServers{} +storages: + for _, s := range cfg.Storages { + // It picks up the first address configured: TLS, TCP or UNIX. + for _, addr := range []string{cfg.TLSListenAddr, cfg.ListenAddr, cfg.SocketPath} { + if addr != "" { + gitalyServers[s.Name] = storage.ServerInfo{ + Address: addr, + Token: cfg.Auth.Token, + } + continue storages + } + } + require.FailNow(t, "no address found on the config") + } + + gitalyServersJSON, err := json.Marshal(gitalyServers) + if err != nil { + t.Fatal(err) + } + + return metadata.Pairs("gitaly-servers", base64.StdEncoding.EncodeToString(gitalyServersJSON)) +} diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index 7a52ce3ee..1a18ac2e9 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -6,8 +6,6 @@ import ( "crypto/elliptic" "crypto/rand" "crypto/x509" - "encoding/base64" - "encoding/json" "encoding/pem" "fmt" "io" @@ -23,10 +21,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config" - "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/storage" "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" - "google.golang.org/grpc/metadata" ) const ( @@ -64,33 +59,6 @@ func GitlabTestStoragePath() string { return filepath.Join(testDirectory, "storage") } -// GitalyServersMetadataFromCfg returns a metadata pair for gitaly-servers to be used in -// inter-gitaly operations. -func GitalyServersMetadataFromCfg(t testing.TB, cfg config.Cfg) metadata.MD { - gitalyServers := storage.GitalyServers{} -storages: - for _, s := range cfg.Storages { - // It picks up the first address configured: TLS, TCP or UNIX. - for _, addr := range []string{cfg.TLSListenAddr, cfg.ListenAddr, cfg.SocketPath} { - if addr != "" { - gitalyServers[s.Name] = storage.ServerInfo{ - Address: addr, - Token: cfg.Auth.Token, - } - continue storages - } - } - require.FailNow(t, "no address found on the config") - } - - gitalyServersJSON, err := json.Marshal(gitalyServers) - if err != nil { - t.Fatal(err) - } - - return metadata.Pairs("gitaly-servers", base64.StdEncoding.EncodeToString(gitalyServersJSON)) -} - // MustRunCommand runs a command with an optional standard input and returns the standard output, or fails. func MustRunCommand(t testing.TB, stdin io.Reader, name string, args ...string) []byte { t.Helper() |