Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuang-Minh Nguyen <qmnguyen@gitlab.com>2023-05-31 13:40:31 +0300
committerQuang-Minh Nguyen <qmnguyen@gitlab.com>2023-05-31 13:40:31 +0300
commitd6a5537c46fa74c7a5b4cad5f9633e0d78f269d4 (patch)
tree57d93af8ef6456ae0b07ceab994fe3292ce1efb9
parentd93eb3873e082e85b3aeb24f02908794cd2dd156 (diff)
parentdaa2152c0c221afb976afe5577486406c283946c (diff)
Merge branch 'pks-tests-extend-sha256-coverage' into 'master'
tests: Extend SHA256 test coverage See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/5856 Merged-by: Quang-Minh Nguyen <qmnguyen@gitlab.com> Approved-by: karthik nayak <knayak@gitlab.com> Co-authored-by: Patrick Steinhardt <psteinhardt@gitlab.com>
-rw-r--r--internal/gitaly/server/server_factory_test.go2
-rw-r--r--internal/gitaly/service/commit/commit_messages_test.go8
-rw-r--r--internal/gitaly/service/commit/count_diverging_commits_test.go7
-rw-r--r--internal/gitaly/service/hook/pack_objects_test.go86
-rw-r--r--internal/gitaly/service/hook/post_receive_test.go8
-rw-r--r--internal/gitaly/service/hook/pre_receive_test.go17
-rw-r--r--internal/gitaly/service/hook/reference_transaction_test.go6
-rw-r--r--internal/gitaly/service/hook/testhelper_test.go12
-rw-r--r--internal/gitaly/service/hook/update_test.go11
-rw-r--r--internal/gitaly/service/ref/branches_test.go34
-rw-r--r--internal/gitaly/service/ref/delete_refs_test.go46
-rw-r--r--internal/gitaly/service/ref/find_refs_by_oid_test.go28
-rw-r--r--internal/gitaly/service/ref/list_refs_test.go9
-rw-r--r--internal/gitaly/service/ref/tag_messages_test.go12
-rw-r--r--internal/gitaly/service/repository/config_test.go15
-rw-r--r--internal/gitaly/service/repository/create_bundle_from_ref_list_test.go19
-rw-r--r--internal/gitaly/service/repository/create_repository_from_url_test.go7
-rw-r--r--internal/gitaly/service/repository/info_attributes_test.go9
-rw-r--r--internal/gitaly/service/repository/optimize_test.go5
-rw-r--r--internal/gitaly/service/repository/rename_test.go27
-rw-r--r--internal/gitaly/service/repository/set_custom_hooks_test.go5
-rw-r--r--internal/gitaly/service/server/disk_stats_test.go2
-rw-r--r--internal/gitaly/service/server/info_test.go2
-rw-r--r--internal/praefect/coordinator_pg_test.go2
-rw-r--r--internal/praefect/coordinator_test.go3
-rw-r--r--internal/praefect/datastore/glsql/testhelper_test.go2
-rw-r--r--internal/praefect/datastore/repository_store_test.go2
-rw-r--r--internal/praefect/datastore/testhelper_test.go2
-rw-r--r--internal/praefect/info_service_test.go4
-rw-r--r--internal/praefect/middleware/errorhandler_test.go3
-rw-r--r--internal/praefect/nodes/local_elector_test.go2
-rw-r--r--internal/praefect/nodes/manager_test.go2
-rw-r--r--internal/praefect/nodes/sql_elector_test.go2
-rw-r--r--internal/praefect/remove_repository_test.go2
-rw-r--r--internal/praefect/replicator_test.go7
-rw-r--r--internal/praefect/repocleaner/repository_test.go14
-rw-r--r--internal/praefect/server_factory_test.go19
-rw-r--r--internal/praefect/server_test.go9
-rw-r--r--internal/praefect/transaction_test.go2
39 files changed, 189 insertions, 265 deletions
diff --git a/internal/gitaly/server/server_factory_test.go b/internal/gitaly/server/server_factory_test.go
index 21811aa03..fba2a4613 100644
--- a/internal/gitaly/server/server_factory_test.go
+++ b/internal/gitaly/server/server_factory_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package server
import (
diff --git a/internal/gitaly/service/commit/commit_messages_test.go b/internal/gitaly/service/commit/commit_messages_test.go
index 0fcdbad38..4a039d4d2 100644
--- a/internal/gitaly/service/commit/commit_messages_test.go
+++ b/internal/gitaly/service/commit/commit_messages_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package commit
import (
@@ -20,7 +18,9 @@ func TestSuccessfulGetCommitMessagesRequest(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupCommitServiceWithRepo(t, ctx)
+ cfg, client := setupCommitService(t, ctx)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
message1 := strings.Repeat("a\n", helper.MaxCommitOrTagMessageSize*2)
message2 := strings.Repeat("b\n", helper.MaxCommitOrTagMessageSize*2)
@@ -62,7 +62,7 @@ func TestFailedGetCommitMessagesRequest(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, _, _, client := setupCommitServiceWithRepo(t, ctx)
+ _, client := setupCommitService(t, ctx)
testCases := []struct {
desc string
diff --git a/internal/gitaly/service/commit/count_diverging_commits_test.go b/internal/gitaly/service/commit/count_diverging_commits_test.go
index 31a9e3fa1..3330971b1 100644
--- a/internal/gitaly/service/commit/count_diverging_commits_test.go
+++ b/internal/gitaly/service/commit/count_diverging_commits_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package commit
import (
@@ -162,9 +160,10 @@ func TestFailedCountDivergentCommitsRequestDueToValidationError(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupCommitServiceWithRepo(t, ctx)
+ cfg, client := setupCommitService(t, ctx)
- revision := []byte("d42783470dc29fde2cf459eb3199ee1d7e3f3a72")
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ revision := []byte(gittest.WriteCommit(t, cfg, repoPath))
for _, tc := range []struct {
desc string
diff --git a/internal/gitaly/service/hook/pack_objects_test.go b/internal/gitaly/service/hook/pack_objects_test.go
index 0e21574cb..610686e43 100644
--- a/internal/gitaly/service/hook/pack_objects_test.go
+++ b/internal/gitaly/service/hook/pack_objects_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package hook
import (
@@ -95,15 +93,14 @@ func testServerPackObjectsHookSeparateContextWithRuntimeDir(t *testing.T, ctx co
ctx1, cancel := context.WithCancel(ctx)
defer cancel()
- repo, repoPath := gittest.CreateRepository(t, ctx1, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, repoPath := gittest.CreateRepository(t, ctx1, cfg)
+ commitID := gittest.WriteCommit(t, cfg, repoPath)
req := &gitalypb.PackObjectsHookWithSidechannelRequest{
Repository: repo,
Args: []string{"pack-objects", "--revs", "--thin", "--stdout", "--progress", "--delta-base-offset"},
}
- const stdin = "3dd08961455abf80ef9115f4afdc1c6f968b503c\n--not\n\n"
+ stdin := commitID.String() + "\n--not\n\n"
start1 := make(chan struct{})
start2 := make(chan struct{})
@@ -355,9 +352,8 @@ func testServerPackObjectsHookUsesCache(t *testing.T, ctx context.Context, runti
s.packObjectsCache = tlc
}})
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ commitID := gittest.WriteCommit(t, cfg, repoPath)
doRequest := func(request *gitalypb.PackObjectsHookWithSidechannelRequest) {
var stdout []byte
@@ -367,7 +363,7 @@ func testServerPackObjectsHookUsesCache(t *testing.T, ctx context.Context, runti
RuntimeDir: runtimeDir,
},
func(c *net.UnixConn) error {
- if _, err := io.WriteString(c, "3dd08961455abf80ef9115f4afdc1c6f968b503c\n--not\n\n"); err != nil {
+ if _, err := io.WriteString(c, commitID.String()+"\n--not\n\n"); err != nil {
return err
}
if err := c.CloseWrite(); err != nil {
@@ -429,25 +425,54 @@ func TestServer_PackObjectsHookWithSidechannel(t *testing.T) {
}
func testServerPackObjectsHookWithSidechannelWithRuntimeDir(t *testing.T, ctx context.Context, runtimeDir string) {
- testCases := []struct {
+ t.Parallel()
+
+ type setupData struct {
+ repo *gitalypb.Repository
+ repoPath string
+ args []string
+ stdin string
+ }
+
+ for _, tc := range []struct {
desc string
- stdin string
- args []string
+ setup func(*testing.T, context.Context, config.Cfg) setupData
}{
{
- desc: "clone 1 branch",
- stdin: "3dd08961455abf80ef9115f4afdc1c6f968b503c\n--not\n\n",
- args: []string{"pack-objects", "--revs", "--thin", "--stdout", "--progress", "--delta-base-offset"},
+ desc: "clone 1 branch",
+ setup: func(t *testing.T, ctx context.Context, cfg config.Cfg) setupData {
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ oid := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("branch"))
+
+ return setupData{
+ repo: repo,
+ repoPath: repoPath,
+ stdin: oid.String() + "\n--not\n\n",
+ args: []string{"pack-objects", "--revs", "--thin", "--stdout", "--progress", "--delta-base-offset"},
+ }
+ },
},
{
- desc: "shallow clone 1 branch",
- stdin: "--shallow 1e292f8fedd741b75372e19097c76d327140c312\n1e292f8fedd741b75372e19097c76d327140c312\n--not\n\n",
- args: []string{"--shallow-file", "", "pack-objects", "--revs", "--thin", "--stdout", "--shallow", "--progress", "--delta-base-offset", "--include-tag"},
+ desc: "shallow clone 1 branch",
+ setup: func(t *testing.T, ctx context.Context, cfg config.Cfg) setupData {
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+
+ firstCommit := gittest.WriteCommit(t, cfg, repoPath)
+ secondCommit := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(firstCommit), gittest.WithBranch("branch"))
+
+ return setupData{
+ repo: repo,
+ repoPath: repoPath,
+ stdin: fmt.Sprintf("--shallow %[1]s\n%[1]s\n--not\n\n", secondCommit),
+ args: []string{"--shallow-file", "", "pack-objects", "--revs", "--thin", "--stdout", "--shallow", "--progress", "--delta-base-offset", "--include-tag"},
+ }
+ },
},
- }
-
- for _, tc := range testCases {
+ } {
+ tc := tc
t.Run(tc.desc, func(t *testing.T) {
+ t.Parallel()
+
cfg := cfgWithCache(t, 0)
logger, hook := test.NewNullLogger()
@@ -460,9 +485,8 @@ func testServerPackObjectsHookWithSidechannelWithRuntimeDir(t *testing.T, ctx co
testserver.WithLogger(logger),
testserver.WithConcurrencyTracker(concurrencyTracker),
)
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+
+ setup := tc.setup(t, ctx, cfg)
var packets []string
ctx, wt, err := hookPkg.SetupSidechannel(
@@ -471,7 +495,7 @@ func testServerPackObjectsHookWithSidechannelWithRuntimeDir(t *testing.T, ctx co
RuntimeDir: runtimeDir,
},
func(c *net.UnixConn) error {
- if _, err := io.WriteString(c, tc.stdin); err != nil {
+ if _, err := io.WriteString(c, setup.stdin); err != nil {
return err
}
if err := c.CloseWrite(); err != nil {
@@ -492,8 +516,8 @@ func testServerPackObjectsHookWithSidechannelWithRuntimeDir(t *testing.T, ctx co
defer conn.Close()
_, err = client.PackObjectsHookWithSidechannel(ctx, &gitalypb.PackObjectsHookWithSidechannelRequest{
- Repository: repo,
- Args: tc.args,
+ Repository: setup.repo,
+ Args: setup.args,
})
require.NoError(t, err)
@@ -517,7 +541,7 @@ func testServerPackObjectsHookWithSidechannelWithRuntimeDir(t *testing.T, ctx co
t,
cfg,
gittest.ExecConfig{Stdin: bytes.NewReader(packdata)},
- "-C", repoPath, "index-pack", "--stdin", "--fix-thin",
+ "-C", setup.repoPath, "index-pack", "--stdin", "--fix-thin",
)
entry := hook.LastEntry()
@@ -630,9 +654,7 @@ func TestServer_PackObjectsHookWithSidechannel_invalidArgument(t *testing.T) {
cfg.SocketPath = runHooksServer(t, cfg, nil)
ctx := testhelper.Context(t)
- repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
testCases := []struct {
desc string
diff --git a/internal/gitaly/service/hook/post_receive_test.go b/internal/gitaly/service/hook/post_receive_test.go
index 651798908..12ab95a8c 100644
--- a/internal/gitaly/service/hook/post_receive_test.go
+++ b/internal/gitaly/service/hook/post_receive_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package hook
import (
@@ -28,8 +26,10 @@ import (
)
func TestPostReceiveInvalidArgument(t *testing.T) {
+ t.Parallel()
+
ctx := testhelper.Context(t)
- _, _, _, client := setupHookService(t, ctx)
+ _, client := setupHookService(t)
stream, err := client.PostReceiveHook(ctx)
require.NoError(t, err)
@@ -69,7 +69,6 @@ func TestHooksMissingStdin(t *testing.T) {
repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
c := gitlab.TestServerOptions{
@@ -199,7 +198,6 @@ To create a merge request for okay, visit:
repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
tempDir := testhelper.TempDir(t)
diff --git a/internal/gitaly/service/hook/pre_receive_test.go b/internal/gitaly/service/hook/pre_receive_test.go
index 15223a0ca..03bc734dc 100644
--- a/internal/gitaly/service/hook/pre_receive_test.go
+++ b/internal/gitaly/service/hook/pre_receive_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package hook
import (
@@ -32,7 +30,7 @@ import (
func TestPreReceiveInvalidArgument(t *testing.T) {
ctx := testhelper.Context(t)
- _, _, _, client := setupHookService(t, ctx)
+ _, client := setupHookService(t)
stream, err := client.PreReceiveHook(ctx)
require.NoError(t, err)
@@ -93,7 +91,6 @@ func TestPreReceiveHook_GitlabAPIAccess(t *testing.T) {
repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
gitObjectDirRel := "git/object/dir"
@@ -263,9 +260,7 @@ func TestPreReceive_APIErrors(t *testing.T) {
cfg.SocketPath = runHooksServer(t, cfg, nil, testserver.WithGitLabClient(gitlabClient))
ctx := testhelper.Context(t)
- repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
client, conn := newHooksClient(t, cfg.SocketPath)
defer conn.Close()
@@ -330,9 +325,7 @@ func TestPreReceiveHook_CustomHookErrors(t *testing.T) {
cfg.SocketPath = runHooksServer(t, cfg, nil, testserver.WithGitLabClient(gitlabClient))
ctx := testhelper.Context(t)
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
customHookReturnCode := int32(128)
customHookReturnMsg := "custom hook error"
@@ -467,9 +460,7 @@ func TestPreReceiveHook_Primary(t *testing.T) {
cfg.SocketPath = runHooksServer(t, cfg, nil, testserver.WithGitLabClient(gitlabClient))
ctx := testhelper.Context(t)
- testRepo, testRepoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ testRepo, testRepoPath := gittest.CreateRepository(t, ctx, cfg)
gittest.WriteCustomHook(t, testRepoPath, "pre-receive", []byte(fmt.Sprintf("#!/usr/bin/env bash\nexit %d", tc.hookExitCode)))
diff --git a/internal/gitaly/service/hook/reference_transaction_test.go b/internal/gitaly/service/hook/reference_transaction_test.go
index ec722b3b0..5f24d234b 100644
--- a/internal/gitaly/service/hook/reference_transaction_test.go
+++ b/internal/gitaly/service/hook/reference_transaction_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package hook
import (
@@ -161,9 +159,7 @@ func TestReferenceTransactionHook(t *testing.T) {
cfg.SocketPath = runHooksServer(t, cfg, nil, testserver.WithBackchannelRegistry(registry))
ctx := testhelper.Context(t)
- repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
hooksPayload, err := git.NewHooksPayload(
cfg,
diff --git a/internal/gitaly/service/hook/testhelper_test.go b/internal/gitaly/service/hook/testhelper_test.go
index f6ab54d5a..f6875413f 100644
--- a/internal/gitaly/service/hook/testhelper_test.go
+++ b/internal/gitaly/service/hook/testhelper_test.go
@@ -1,12 +1,8 @@
-//go:build !gitaly_test_sha256
-
package hook
import (
- "context"
"testing"
- "gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config"
gitalyhook "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/hook"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service"
@@ -23,7 +19,7 @@ func TestMain(m *testing.M) {
testhelper.Run(m)
}
-func setupHookService(tb testing.TB, ctx context.Context) (config.Cfg, *gitalypb.Repository, string, gitalypb.HookServiceClient) {
+func setupHookService(tb testing.TB) (config.Cfg, gitalypb.HookServiceClient) {
tb.Helper()
cfg := testcfg.Build(tb)
@@ -31,11 +27,7 @@ func setupHookService(tb testing.TB, ctx context.Context) (config.Cfg, *gitalypb
client, conn := newHooksClient(tb, cfg.SocketPath)
tb.Cleanup(func() { conn.Close() })
- repo, repoPath := gittest.CreateRepository(tb, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
-
- return cfg, repo, repoPath, client
+ return cfg, client
}
func newHooksClient(tb testing.TB, serverSocketPath string) (gitalypb.HookServiceClient, *grpc.ClientConn) {
diff --git a/internal/gitaly/service/hook/update_test.go b/internal/gitaly/service/hook/update_test.go
index 257e05c6e..fed08a316 100644
--- a/internal/gitaly/service/hook/update_test.go
+++ b/internal/gitaly/service/hook/update_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package hook
import (
@@ -37,8 +35,11 @@ func TestUpdateInvalidArgument(t *testing.T) {
}
func TestUpdate_CustomHooks(t *testing.T) {
+ t.Parallel()
+
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupHookService(t, ctx)
+ cfg, client := setupHookService(t)
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
hooksPayload, err := git.NewHooksPayload(
cfg,
@@ -62,8 +63,8 @@ func TestUpdate_CustomHooks(t *testing.T) {
req := gitalypb.UpdateHookRequest{
Repository: repo,
Ref: []byte("master"),
- OldValue: strings.Repeat("a", 40),
- NewValue: strings.Repeat("b", 40),
+ OldValue: strings.Repeat("a", gittest.DefaultObjectHash.EncodedLen()),
+ NewValue: strings.Repeat("b", gittest.DefaultObjectHash.EncodedLen()),
EnvironmentVariables: envVars,
}
diff --git a/internal/gitaly/service/ref/branches_test.go b/internal/gitaly/service/ref/branches_test.go
index cea7ef9f4..209d0bed1 100644
--- a/internal/gitaly/service/ref/branches_test.go
+++ b/internal/gitaly/service/ref/branches_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package ref
import (
@@ -7,6 +5,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v16/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
@@ -15,29 +14,27 @@ import (
)
func TestSuccessfulFindBranchRequest(t *testing.T) {
- ctx := testhelper.Context(t)
+ t.Parallel()
- cfg, repoProto, _, client := setupRefService(t, ctx)
+ ctx := testhelper.Context(t)
+ cfg, client := setupRefServiceWithoutRepo(t)
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
branchesByName := make(map[git.ReferenceName]*gitalypb.Branch)
- for branchName, revision := range map[git.ReferenceName]git.Revision{
- "refs/heads/branch": "refs/heads/master~0",
- "refs/heads/heads/branch": "refs/heads/master~1",
- "refs/heads/refs/heads/branch": "refs/heads/master~2",
+ for _, branchName := range []string{
+ "refs/heads/branch",
+ "refs/heads/heads/branch",
+ "refs/heads/refs/heads/branch",
} {
- oid, err := repo.ResolveRevision(ctx, revision)
- require.NoError(t, err)
+ oid := gittest.WriteCommit(t, cfg, repoPath, gittest.WithReference(branchName), gittest.WithMessage(branchName))
- err = repo.UpdateRef(ctx, branchName, oid, "")
+ commit, err := repo.ReadCommit(ctx, oid.Revision())
require.NoError(t, err)
- commit, err := repo.ReadCommit(ctx, branchName.Revision())
- require.NoError(t, err)
-
- branchesByName[branchName] = &gitalypb.Branch{
- Name: []byte(branchName.String()[len("refs/heads/"):]),
+ branchesByName[git.ReferenceName(branchName)] = &gitalypb.Branch{
+ Name: []byte(branchName[len("refs/heads/"):]),
TargetCommit: commit,
}
}
@@ -84,8 +81,11 @@ func TestSuccessfulFindBranchRequest(t *testing.T) {
}
func TestFailedFindBranchRequest(t *testing.T) {
+ t.Parallel()
+
ctx := testhelper.Context(t)
- _, repo, _, client := setupRefService(t, ctx)
+ cfg, client := setupRefServiceWithoutRepo(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
testCases := []struct {
desc string
diff --git a/internal/gitaly/service/ref/delete_refs_test.go b/internal/gitaly/service/ref/delete_refs_test.go
index 831c21663..9ff99e32a 100644
--- a/internal/gitaly/service/ref/delete_refs_test.go
+++ b/internal/gitaly/service/ref/delete_refs_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package ref
import (
@@ -57,14 +55,18 @@ func TestDeleteRefs_successful(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
-
- gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/delete/a", "b83d6e391c22777fca1ed3012fce84f633d7fed0")
- gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/also-delete/b", "1b12f15a11fc6e62177bef08f47bc7b5ce50b141")
- gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/keep/c", "498214de67004b1da3d820901307bed2a68a8ef6")
- gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/also-keep/d", "b83d6e391c22777fca1ed3012fce84f633d7fed0")
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+
+ for _, ref := range []string{
+ "refs/heads/master",
+ "refs/delete/a",
+ "refs/also-delete/b",
+ "refs/keep/c",
+ "refs/also-keep/d",
+ } {
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage(ref), gittest.WithReference(ref))
+ }
+
gittest.Exec(t, cfg, "-C", repoPath, "symbolic-ref", "refs/delete/symbolic-a", "refs/delete/a")
gittest.Exec(t, cfg, "-C", repoPath, "symbolic-ref", "refs/delete/symbolic-c", "refs/keep/c")
@@ -151,9 +153,9 @@ func TestDeleteRefs_transaction(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
- repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch))
+
txManager.Reset()
tc.request.Repository = repo
@@ -171,7 +173,8 @@ func TestDeleteRefs_invalidRefFormat(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRefService(t, ctx)
+ cfg, client := setupRefServiceWithoutRepo(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
request := &gitalypb.DeleteRefsRequest{
Repository: repo,
@@ -197,7 +200,11 @@ func TestDeleteRefs_refLocked(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repoProto, _, client := setupRefService(t, ctx)
+ cfg, client := setupRefServiceWithoutRepo(t)
+
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ oldValue := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master"))
+ newValue := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("new"))
request := &gitalypb.DeleteRefsRequest{
Repository: repoProto,
@@ -205,8 +212,6 @@ func TestDeleteRefs_refLocked(t *testing.T) {
}
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- oldValue, err := repo.ResolveRevision(ctx, git.Revision("refs/heads/master"))
- require.NoError(t, err)
updater, err := updateref.New(ctx, repo)
require.NoError(t, err)
@@ -215,7 +220,7 @@ func TestDeleteRefs_refLocked(t *testing.T) {
require.NoError(t, updater.Start())
require.NoError(t, updater.Update(
git.ReferenceName("refs/heads/master"),
- "0b4bc9a49b562e85de7cc9e834518ea6828729b9",
+ newValue,
oldValue,
))
require.NoError(t, updater.Prepare())
@@ -237,9 +242,10 @@ func TestDeleteRefs_refLocked(t *testing.T) {
func TestDeleteRefs_validation(t *testing.T) {
t.Parallel()
- ctx := testhelper.Context(t)
- _, repo, _, client := setupRefService(t, ctx)
+ ctx := testhelper.Context(t)
+ cfg, client := setupRefServiceWithoutRepo(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
testCases := []struct {
desc string
diff --git a/internal/gitaly/service/ref/find_refs_by_oid_test.go b/internal/gitaly/service/ref/find_refs_by_oid_test.go
index efc7d69b6..d1eaeac86 100644
--- a/internal/gitaly/service/ref/find_refs_by_oid_test.go
+++ b/internal/gitaly/service/ref/find_refs_by_oid_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package ref
import (
@@ -21,8 +19,9 @@ func TestFindRefsByOID_successful(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupRefService(t, ctx)
+ cfg, client := setupRefServiceWithoutRepo(t)
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
oid := gittest.WriteCommit(t, cfg, repoPath)
gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/branch-1", string(oid))
@@ -131,9 +130,7 @@ func TestFindRefsByOID_failure(t *testing.T) {
{
desc: "no ref exists for OID",
setup: func(t *testing.T) (*gitalypb.FindRefsByOIDRequest, error) {
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
oid := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("no ref exists for OID"))
return &gitalypb.FindRefsByOIDRequest{
@@ -145,9 +142,7 @@ func TestFindRefsByOID_failure(t *testing.T) {
{
desc: "repository is corrupted",
setup: func(t *testing.T) (*gitalypb.FindRefsByOIDRequest, error) {
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
oid := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("no ref exists for OID"))
gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/corrupted-repo-branch", oid.String())
@@ -162,9 +157,7 @@ func TestFindRefsByOID_failure(t *testing.T) {
{
desc: "repository is missing",
setup: func(t *testing.T) (*gitalypb.FindRefsByOIDRequest, error) {
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
oid := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("repository is missing"))
require.NoError(t, os.RemoveAll(repoPath))
@@ -177,9 +170,7 @@ func TestFindRefsByOID_failure(t *testing.T) {
{
desc: "oid is not a commit",
setup: func(t *testing.T) (*gitalypb.FindRefsByOIDRequest, error) {
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
oid := gittest.WriteBlob(t, cfg, repoPath, []byte("the blob"))
return &gitalypb.FindRefsByOIDRequest{
@@ -191,9 +182,7 @@ func TestFindRefsByOID_failure(t *testing.T) {
{
desc: "oid prefix too short",
setup: func(t *testing.T) (*gitalypb.FindRefsByOIDRequest, error) {
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
oid := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("oid prefix too short"))
gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/short-oid", oid.String())
@@ -224,7 +213,8 @@ func TestFindRefsByOID_validation(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRefService(t, ctx)
+ cfg, client := setupRefServiceWithoutRepo(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
testCases := map[string]struct {
req *gitalypb.FindRefsByOIDRequest
diff --git a/internal/gitaly/service/ref/list_refs_test.go b/internal/gitaly/service/ref/list_refs_test.go
index 69d9dd32d..9fb7504bb 100644
--- a/internal/gitaly/service/ref/list_refs_test.go
+++ b/internal/gitaly/service/ref/list_refs_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package ref
import (
@@ -20,7 +18,7 @@ func TestServer_ListRefs(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, _, _, client := setupRefService(t, ctx)
+ cfg, client := setupRefServiceWithoutRepo(t)
repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
@@ -255,8 +253,11 @@ func TestServer_ListRefs(t *testing.T) {
func TestListRefs_validate(t *testing.T) {
t.Parallel()
+
ctx := testhelper.Context(t)
- _, repo, _, client := setupRefService(t, ctx)
+ cfg, client := setupRefServiceWithoutRepo(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
+
for _, tc := range []struct {
desc string
req *gitalypb.ListRefsRequest
diff --git a/internal/gitaly/service/ref/tag_messages_test.go b/internal/gitaly/service/ref/tag_messages_test.go
index fe691b8a0..3136c3cfb 100644
--- a/internal/gitaly/service/ref/tag_messages_test.go
+++ b/internal/gitaly/service/ref/tag_messages_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package ref
import (
@@ -20,13 +18,17 @@ func TestSuccessfulGetTagMessagesRequest(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupRefService(t, ctx)
+ cfg, client := setupRefServiceWithoutRepo(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
message1 := strings.Repeat("a", helper.MaxCommitOrTagMessageSize*2)
message2 := strings.Repeat("b", helper.MaxCommitOrTagMessageSize)
- tag1ID := gittest.WriteTag(t, cfg, repoPath, "big-tag-1", "master", gittest.WriteTagConfig{Message: message1})
- tag2ID := gittest.WriteTag(t, cfg, repoPath, "big-tag-2", "master~", gittest.WriteTagConfig{Message: message2})
+ commit1 := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("big-tag-1"))
+ commit2 := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("big-tag-2"))
+ tag1ID := gittest.WriteTag(t, cfg, repoPath, "big-tag-1", commit1.Revision(), gittest.WriteTagConfig{Message: message1})
+ tag2ID := gittest.WriteTag(t, cfg, repoPath, "big-tag-2", commit2.Revision(), gittest.WriteTagConfig{Message: message2})
request := &gitalypb.GetTagMessagesRequest{
Repository: repo,
diff --git a/internal/gitaly/service/repository/config_test.go b/internal/gitaly/service/repository/config_test.go
index 1dd890c70..11c9c086b 100644
--- a/internal/gitaly/service/repository/config_test.go
+++ b/internal/gitaly/service/repository/config_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package repository
import (
@@ -48,14 +46,15 @@ func TestGetConfig(t *testing.T) {
}
t.Run("normal repo", func(t *testing.T) {
- repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
config, err := getConfig(t, client, repo)
require.NoError(t, err)
- expectedConfig := "[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = true\n"
+ expectedConfig := gittest.ObjectHashDependent(t, map[string]string{
+ "sha1": "[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = true\n",
+ "sha256": "[core]\n\trepositoryformatversion = 1\n\tfilemode = true\n\tbare = true\n[extensions]\n\tobjectformat = sha256\n",
+ })
if runtime.GOOS == "darwin" {
expectedConfig = expectedConfig + "\tignorecase = true\n\tprecomposeunicode = true\n"
@@ -64,9 +63,7 @@ func TestGetConfig(t *testing.T) {
})
t.Run("missing config", func(t *testing.T) {
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
configPath := filepath.Join(repoPath, "config")
require.NoError(t, os.Remove(configPath))
diff --git a/internal/gitaly/service/repository/create_bundle_from_ref_list_test.go b/internal/gitaly/service/repository/create_bundle_from_ref_list_test.go
index ca3d7950f..eb222429e 100644
--- a/internal/gitaly/service/repository/create_bundle_from_ref_list_test.go
+++ b/internal/gitaly/service/repository/create_bundle_from_ref_list_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package repository
import (
@@ -13,7 +11,6 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/helper/perm"
- "gitlab.com/gitlab-org/gitaly/v16/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v16/streamio"
@@ -25,10 +22,12 @@ func TestCreateBundleFromRefList_success(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupRepositoryService(t, ctx)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
// Create a work tree with a HEAD pointing to a commit that is missing. CreateBundle should
// clean this up before creating the bundle.
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ masterOID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("master"), gittest.WithBranch("master"))
sha := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("branch"))
require.NoError(t, os.MkdirAll(filepath.Join(repoPath, "gitlab-worktree"), perm.SharedDir))
@@ -39,8 +38,6 @@ func TestCreateBundleFromRefList_success(t *testing.T) {
gittest.Exec(t, cfg, "-C", repoPath, "branch", "-D", "branch")
require.NoError(t, os.Remove(filepath.Join(repoPath, "objects", sha.String()[0:2], sha.String()[2:])))
- masterOID := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/master"))
-
c, err := client.CreateBundleFromRefList(ctx)
require.NoError(t, err)
@@ -75,9 +72,10 @@ func TestCreateBundleFromRefList_missing_ref(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupRepositoryService(t, ctx)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
- masterOID := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/master"))
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ commitOID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master"))
c, err := client.CreateBundleFromRefList(ctx)
require.NoError(t, err)
@@ -106,14 +104,15 @@ func TestCreateBundleFromRefList_missing_ref(t *testing.T) {
output := gittest.Exec(t, cfg, "-C", repoPath, "bundle", "verify", bundle.Name())
- require.Contains(t, string(output), fmt.Sprintf("The bundle contains this ref:\n%s refs/heads/master", masterOID))
+ require.Contains(t, string(output), fmt.Sprintf("The bundle contains this ref:\n%s refs/heads/master", commitOID))
}
func TestCreateBundleFromRefList_validations(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRepositoryService(t, ctx)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
testCases := []struct {
desc string
diff --git a/internal/gitaly/service/repository/create_repository_from_url_test.go b/internal/gitaly/service/repository/create_repository_from_url_test.go
index 695702d63..f90a63c37 100644
--- a/internal/gitaly/service/repository/create_repository_from_url_test.go
+++ b/internal/gitaly/service/repository/create_repository_from_url_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package repository
import (
@@ -29,9 +27,12 @@ func TestCreateRepositoryFromURL_successful(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, _, repoPath, client := setupRepositoryService(t, ctx)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
gitCmdFactory := gittest.NewCommandFactory(t, cfg)
+ _, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch))
+
importedRepo := &gitalypb.Repository{
RelativePath: "imports/test-repo-imported.git",
StorageName: cfg.Storages[0].Name,
diff --git a/internal/gitaly/service/repository/info_attributes_test.go b/internal/gitaly/service/repository/info_attributes_test.go
index c6e7849b4..44a24e80f 100644
--- a/internal/gitaly/service/repository/info_attributes_test.go
+++ b/internal/gitaly/service/repository/info_attributes_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package repository
import (
@@ -10,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/helper/perm"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
@@ -22,7 +21,8 @@ func TestGetInfoAttributesExisting(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, repoPath, client := setupRepositoryService(t, ctx)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
infoPath := filepath.Join(repoPath, "info")
require.NoError(t, os.MkdirAll(infoPath, perm.SharedDir))
@@ -51,7 +51,8 @@ func TestGetInfoAttributesNonExisting(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRepositoryService(t, ctx)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
request := &gitalypb.GetInfoAttributesRequest{Repository: repo}
diff --git a/internal/gitaly/service/repository/optimize_test.go b/internal/gitaly/service/repository/optimize_test.go
index f94718a03..54a509d80 100644
--- a/internal/gitaly/service/repository/optimize_test.go
+++ b/internal/gitaly/service/repository/optimize_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package repository
import (
@@ -329,7 +327,8 @@ func TestOptimizeRepository_validation(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, _, client := setupRepositoryService(t, ctx)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
for _, tc := range []struct {
desc string
diff --git a/internal/gitaly/service/repository/rename_test.go b/internal/gitaly/service/repository/rename_test.go
index 72557b18e..221533938 100644
--- a/internal/gitaly/service/repository/rename_test.go
+++ b/internal/gitaly/service/repository/rename_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package repository
import (
@@ -9,7 +7,6 @@ import (
"testing"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitaly/v16/internal/git"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper"
@@ -23,7 +20,9 @@ func TestRenameRepositorySuccess(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, originalRepo, originalPath, client := setupRepositoryService(t, ctx)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
+ originalRepo, originalPath := gittest.CreateRepository(t, ctx, cfg)
+ commitID := gittest.WriteCommit(t, cfg, originalPath)
const targetPath = "a-new-location"
_, err := client.RenameRepository(ctx, &gitalypb.RenameRepositoryRequest{
@@ -55,8 +54,8 @@ func TestRenameRepositorySuccess(t *testing.T) {
require.DirExists(t, newDirectory)
require.True(t, storage.IsGitDirectory(newDirectory), "moved Git repository has been corrupted")
- // ensure the git directory that got renamed contains a sha in the seed repo
- gittest.RequireObjectExists(t, cfg, newDirectory, git.ObjectID("913c66a37b4a45b9769037c55c2d238bd0942d2e"))
+ // ensure the git directory that got renamed contains the original commit.
+ gittest.RequireObjectExists(t, cfg, newDirectory, commitID)
}
func TestRenameRepositoryDestinationExists(t *testing.T) {
@@ -66,18 +65,11 @@ func TestRenameRepositoryDestinationExists(t *testing.T) {
cfg, client := setupRepositoryServiceWithoutRepo(t)
- existingDestinationRepo := &gitalypb.Repository{StorageName: cfg.Storages[0].Name, RelativePath: "repository-1"}
- _, err := client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{Repository: existingDestinationRepo})
- require.NoError(t, err)
-
- renamedRepo := &gitalypb.Repository{StorageName: cfg.Storages[0].Name, RelativePath: "repository-2"}
- _, err = client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{Repository: renamedRepo})
- require.NoError(t, err)
-
- destinationRepoPath := filepath.Join(cfg.Storages[0].Path, gittest.GetReplicaPath(t, ctx, cfg, existingDestinationRepo))
+ existingDestinationRepo, destinationRepoPath := gittest.CreateRepository(t, ctx, cfg)
commitID := gittest.WriteCommit(t, cfg, destinationRepoPath)
+ renamedRepo, _ := gittest.CreateRepository(t, ctx, cfg)
- _, err = client.RenameRepository(ctx, &gitalypb.RenameRepositoryRequest{
+ _, err := client.RenameRepository(ctx, &gitalypb.RenameRepositoryRequest{
Repository: renamedRepo,
RelativePath: existingDestinationRepo.RelativePath,
})
@@ -92,7 +84,8 @@ func TestRenameRepositoryInvalidRequest(t *testing.T) {
ctx := testhelper.Context(t)
- _, repo, repoPath, client := setupRepositoryService(t, ctx)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
storagePath := strings.TrimSuffix(repoPath, "/"+repo.RelativePath)
testCases := []struct {
diff --git a/internal/gitaly/service/repository/set_custom_hooks_test.go b/internal/gitaly/service/repository/set_custom_hooks_test.go
index 517b31314..0ee8e8391 100644
--- a/internal/gitaly/service/repository/set_custom_hooks_test.go
+++ b/internal/gitaly/service/repository/set_custom_hooks_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package repository
import (
@@ -240,7 +238,8 @@ func TestSetCustomHooks_corruptTar(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
- _, repo, _, client := setupRepositoryService(t, ctx)
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg)
writer, closeStream := tc.streamWriter(t, ctx, repo, client)
archivePath := mustCreateCorruptHooksArchive(t)
diff --git a/internal/gitaly/service/server/disk_stats_test.go b/internal/gitaly/service/server/disk_stats_test.go
index 8f014e338..a6f5bf083 100644
--- a/internal/gitaly/service/server/disk_stats_test.go
+++ b/internal/gitaly/service/server/disk_stats_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package server
import (
diff --git a/internal/gitaly/service/server/info_test.go b/internal/gitaly/service/server/info_test.go
index 19d5c34c2..b13666b38 100644
--- a/internal/gitaly/service/server/info_test.go
+++ b/internal/gitaly/service/server/info_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package server
import (
diff --git a/internal/praefect/coordinator_pg_test.go b/internal/praefect/coordinator_pg_test.go
index fa8820f48..428139c9a 100644
--- a/internal/praefect/coordinator_pg_test.go
+++ b/internal/praefect/coordinator_pg_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package praefect
import (
diff --git a/internal/praefect/coordinator_test.go b/internal/praefect/coordinator_test.go
index 9106176c9..d843f382a 100644
--- a/internal/praefect/coordinator_test.go
+++ b/internal/praefect/coordinator_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package praefect
import (
@@ -2093,7 +2091,6 @@ func TestCoordinator_grpcErrorHandling(t *testing.T) {
repoProto, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
for _, tc := range []struct {
diff --git a/internal/praefect/datastore/glsql/testhelper_test.go b/internal/praefect/datastore/glsql/testhelper_test.go
index da5cd0e1e..cf0831c63 100644
--- a/internal/praefect/datastore/glsql/testhelper_test.go
+++ b/internal/praefect/datastore/glsql/testhelper_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package glsql
import (
diff --git a/internal/praefect/datastore/repository_store_test.go b/internal/praefect/datastore/repository_store_test.go
index 03339dd09..c1a59cb98 100644
--- a/internal/praefect/datastore/repository_store_test.go
+++ b/internal/praefect/datastore/repository_store_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package datastore
import (
diff --git a/internal/praefect/datastore/testhelper_test.go b/internal/praefect/datastore/testhelper_test.go
index 2ecc3619b..1a47b041a 100644
--- a/internal/praefect/datastore/testhelper_test.go
+++ b/internal/praefect/datastore/testhelper_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package datastore
import (
diff --git a/internal/praefect/info_service_test.go b/internal/praefect/info_service_test.go
index e1f989149..882f95f4f 100644
--- a/internal/praefect/info_service_test.go
+++ b/internal/praefect/info_service_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package praefect
import (
@@ -126,7 +124,7 @@ func TestInfoService_RepositoryReplicas(t *testing.T) {
// The helper was implemented with the test server in mind. Here we need use the virtual storage's name
// as the storage and the path of the storage we want to modify the replica in.
gconfig.Cfg{Storages: []gconfig.Storage{{Name: virtualStorage, Path: cfgs[1].Storages[0].Path}}},
- gittest.CreateRepositoryConfig{Seed: gittest.SeedGitLabTest, ClientConn: cc},
+ gittest.CreateRepositoryConfig{ClientConn: cc},
)
// create a commit in the second replica so we can check that its checksum is different than the primary
diff --git a/internal/praefect/middleware/errorhandler_test.go b/internal/praefect/middleware/errorhandler_test.go
index 18e689ecf..e43319b63 100644
--- a/internal/praefect/middleware/errorhandler_test.go
+++ b/internal/praefect/middleware/errorhandler_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package middleware
import (
@@ -100,7 +98,6 @@ func TestStreamInterceptor(t *testing.T) {
cfg := testcfg.Build(t)
repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
for i := 0; i < threshold; i++ {
diff --git a/internal/praefect/nodes/local_elector_test.go b/internal/praefect/nodes/local_elector_test.go
index 8db77d16d..fb5c681d2 100644
--- a/internal/praefect/nodes/local_elector_test.go
+++ b/internal/praefect/nodes/local_elector_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package nodes
import (
diff --git a/internal/praefect/nodes/manager_test.go b/internal/praefect/nodes/manager_test.go
index 797576d9f..a6bbb1151 100644
--- a/internal/praefect/nodes/manager_test.go
+++ b/internal/praefect/nodes/manager_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package nodes
import (
diff --git a/internal/praefect/nodes/sql_elector_test.go b/internal/praefect/nodes/sql_elector_test.go
index 65fa7271e..8d9c0d40b 100644
--- a/internal/praefect/nodes/sql_elector_test.go
+++ b/internal/praefect/nodes/sql_elector_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package nodes
import (
diff --git a/internal/praefect/remove_repository_test.go b/internal/praefect/remove_repository_test.go
index fb91f2efc..929c5de10 100644
--- a/internal/praefect/remove_repository_test.go
+++ b/internal/praefect/remove_repository_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package praefect
import (
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go
index 3114e3d05..b78fca253 100644
--- a/internal/praefect/replicator_test.go
+++ b/internal/praefect/replicator_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package praefect
import (
@@ -48,7 +46,6 @@ func TestReplMgr_ProcessBacklog(t *testing.T) {
primaryCfg := testcfg.Build(t, testcfg.WithStorages("primary"))
testRepoProto, testRepoPath := gittest.CreateRepository(t, ctx, primaryCfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
primaryCfg.SocketPath = testserver.RunGitalyServer(t, primaryCfg, setup.RegisterAll, testserver.WithDisablePraefect())
@@ -264,14 +261,12 @@ func TestConfirmReplication(t *testing.T) {
testRepoA, testRepoAPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
srvSocketPath := testserver.RunGitalyServer(t, cfg, setup.RegisterAll, testserver.WithDisablePraefect())
testRepoB, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
connOpts := []grpc.DialOption{
@@ -334,7 +329,6 @@ func TestProcessBacklog_FailedJobs(t *testing.T) {
primaryCfg := testcfg.Build(t, testcfg.WithStorages("default"))
testRepo, _ := gittest.CreateRepository(t, ctx, primaryCfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
primaryAddr := testserver.RunGitalyServer(t, primaryCfg, setup.RegisterAll, testserver.WithDisablePraefect())
@@ -448,7 +442,6 @@ func TestProcessBacklog_Success(t *testing.T) {
testRepo, _ := gittest.CreateRepository(t, ctx, primaryCfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
backupCfg := testcfg.Build(t, testcfg.WithStorages("backup"))
diff --git a/internal/praefect/repocleaner/repository_test.go b/internal/praefect/repocleaner/repository_test.go
index 4cd415900..aaae9df90 100644
--- a/internal/praefect/repocleaner/repository_test.go
+++ b/internal/praefect/repocleaner/repository_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package repocleaner
import (
@@ -80,61 +78,50 @@ func TestRunner_Run(t *testing.T) {
gittest.CreateRepository(t, ctx, g1Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: repo1RelPath,
- Seed: gittest.SeedGitLabTest,
})
gittest.CreateRepository(t, ctx, g1Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: repo2RelPath,
- Seed: gittest.SeedGitLabTest,
})
gittest.CreateRepository(t, ctx, g1Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: repo3RelPath,
- Seed: gittest.SeedGitLabTest,
})
_, repo4Path := gittest.CreateRepository(t, ctx, g1Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: "repo-4.git",
- Seed: gittest.SeedGitLabTest,
})
require.NoError(t, os.Chtimes(repo4Path, time.Now().Add(-25*time.Hour), time.Now().Add(-25*time.Hour)))
gittest.CreateRepository(t, ctx, g2Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: repo1RelPath,
- Seed: gittest.SeedGitLabTest,
})
gittest.CreateRepository(t, ctx, g2Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: repo2RelPath,
- Seed: gittest.SeedGitLabTest,
})
_, repo4Path = gittest.CreateRepository(t, ctx, g2Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: "repo-4.git",
- Seed: gittest.SeedGitLabTest,
})
require.NoError(t, os.Chtimes(repo4Path, time.Now().Add(-25*time.Hour), time.Now().Add(-25*time.Hour)))
gittest.CreateRepository(t, ctx, g3Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: repo1RelPath,
- Seed: gittest.SeedGitLabTest,
})
gittest.CreateRepository(t, ctx, g3Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: repo2RelPath,
- Seed: gittest.SeedGitLabTest,
})
gittest.CreateRepository(t, ctx, g3Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: repo3RelPath,
- Seed: gittest.SeedGitLabTest,
})
_, repo4Path = gittest.CreateRepository(t, ctx, g3Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: "repo-4.git",
- Seed: gittest.SeedGitLabTest,
})
require.NoError(t, os.Chtimes(repo4Path, time.Now().Add(-25*time.Hour), time.Now().Add(-25*time.Hour)))
@@ -258,7 +245,6 @@ func TestRunner_Run_noAvailableStorages(t *testing.T) {
_, repoPath := gittest.CreateRepository(t, ctx, g1Cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
RelativePath: repo1RelPath,
- Seed: gittest.SeedGitLabTest,
})
require.NoError(t, os.Chtimes(repoPath, time.Now().Add(-25*time.Hour), time.Now().Add(-25*time.Hour)))
diff --git a/internal/praefect/server_factory_test.go b/internal/praefect/server_factory_test.go
index e0f3a3915..834699454 100644
--- a/internal/praefect/server_factory_test.go
+++ b/internal/praefect/server_factory_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package praefect
import (
@@ -13,6 +11,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v16/internal/bootstrap/starter"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/git"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
gconfig "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service/setup"
@@ -20,7 +19,6 @@ import (
"gitlab.com/gitlab-org/gitaly/v16/internal/grpc/client"
"gitlab.com/gitlab-org/gitaly/v16/internal/grpc/listenmux"
"gitlab.com/gitlab-org/gitaly/v16/internal/grpc/sidechannel"
- "gitlab.com/gitlab-org/gitaly/v16/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v16/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/v16/internal/praefect/datastore"
"gitlab.com/gitlab-org/gitaly/v16/internal/praefect/nodes"
@@ -48,8 +46,8 @@ func TestServerFactory(t *testing.T) {
repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
+ revision := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch))
certificate := testhelper.GenerateCertificate(t)
@@ -74,7 +72,6 @@ func TestServerFactory(t *testing.T) {
}
repo.StorageName = conf.VirtualStorages[0].Name // storage must be re-written to virtual to be properly redirected by praefect
- revision := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "HEAD"))
logger := testhelper.NewDiscardingLogEntry(t)
queue := datastore.NewPostgresReplicationEventQueue(testdb.New(t))
@@ -117,7 +114,7 @@ func TestServerFactory(t *testing.T) {
Revision: []byte(revision),
})
require.NoError(t, err)
- require.Equal(t, revision, resp.Commit.Id)
+ require.Equal(t, revision.String(), resp.Commit.Id)
}
checkSidechannelGitaly := func(t *testing.T, ctx context.Context, addr string, creds credentials.TransportCredentials) {
@@ -141,14 +138,10 @@ func TestServerFactory(t *testing.T) {
var pack []byte
ctx, waiter := sidechannel.RegisterSidechannel(ctx, registry, func(conn *sidechannel.ClientConn) error {
- // 1e292f8fedd741b75372e19097c76d327140c312 is refs/heads/master of the test repo
- const message = `003cwant 1e292f8fedd741b75372e19097c76d327140c312 ofs-delta
-00000009done
-`
+ gittest.WritePktlinef(t, conn, "want %s ofs-delta", revision)
+ gittest.WritePktlineFlush(t, conn)
+ gittest.WritePktlineString(t, conn, "done")
- if _, err := io.WriteString(conn, message); err != nil {
- return err
- }
if err := conn.CloseWrite(); err != nil {
return err
}
diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go
index b9eb1544a..c314d374b 100644
--- a/internal/praefect/server_test.go
+++ b/internal/praefect/server_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package praefect
import (
@@ -20,6 +18,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v16/internal/datastructure"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/git"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
gconfig "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service"
@@ -505,7 +504,6 @@ func TestRemoveRepository(t *testing.T) {
gitalyCfgs[i] = testcfg.Build(t, testcfg.WithStorages(name))
repos[i], _ = gittest.CreateRepository(t, ctx, gitalyCfgs[i], gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
RelativePath: t.Name(),
})
@@ -820,10 +818,10 @@ func TestProxyWrites(t *testing.T) {
ctx := testhelper.Context(t)
cfg := testcfg.Build(t)
- repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch))
rs := datastore.MockRepositoryStore{
GetConsistentStoragesFunc: func(ctx context.Context, virtualStorage, relativePath string) (string, *datastructure.Set[string], error) {
@@ -1016,7 +1014,6 @@ func TestErrorThreshold(t *testing.T) {
repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
- Seed: gittest.SeedGitLabTest,
})
node := nodeMgr.Nodes()["default"][0]
diff --git a/internal/praefect/transaction_test.go b/internal/praefect/transaction_test.go
index 16bf0678d..a6216cb61 100644
--- a/internal/praefect/transaction_test.go
+++ b/internal/praefect/transaction_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package praefect
import (