diff options
author | Quang-Minh Nguyen <qmnguyen@gitlab.com> | 2023-08-15 15:58:07 +0300 |
---|---|---|
committer | Quang-Minh Nguyen <qmnguyen@gitlab.com> | 2023-08-15 15:58:07 +0300 |
commit | b2a3b6ba03e6f2c2ad60582733fd27f050d8aa3f (patch) | |
tree | 08439d48b3131c7e8d0fd560bb2b3cb0ded50e6a | |
parent | 3cd27d67e1d43ed7c7ca1d50e59c1bc161be8784 (diff) | |
parent | c84c94f440bc4aac215bc41d8b21702bb99d5dba (diff) |
Merge branch 'pks-get-raw-changes-sha256' into 'master'
repository: Support SHA256 in GetRawChanges
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/6205
Merged-by: Quang-Minh Nguyen <qmnguyen@gitlab.com>
Approved-by: Quang-Minh Nguyen <qmnguyen@gitlab.com>
Reviewed-by: James Fargher <jfargher@gitlab.com>
Reviewed-by: Patrick Steinhardt <psteinhardt@gitlab.com>
Co-authored-by: Patrick Steinhardt <psteinhardt@gitlab.com>
39 files changed, 424 insertions, 409 deletions
diff --git a/internal/gitaly/service/repository/apply_gitattributes_test.go b/internal/gitaly/service/repository/apply_gitattributes_test.go index aac1d1365..0723c0076 100644 --- a/internal/gitaly/service/repository/apply_gitattributes_test.go +++ b/internal/gitaly/service/repository/apply_gitattributes_test.go @@ -26,7 +26,7 @@ func TestApplyGitattributes_successful(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, repoPath := gittest.CreateRepository(t, ctx, cfg) gitattributesContent := "pattern attr=value" @@ -221,7 +221,7 @@ func TestApplyGitattributes_failure(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, _ := gittest.CreateRepository(t, ctx, cfg) for _, tc := range []struct { diff --git a/internal/gitaly/service/repository/archive_test.go b/internal/gitaly/service/repository/archive_test.go index 9fa078f1d..566fac245 100644 --- a/internal/gitaly/service/repository/archive_test.go +++ b/internal/gitaly/service/repository/archive_test.go @@ -446,7 +446,7 @@ func TestGetArchive_pathInjection(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) // It used to be possible to inject options into `git-archive(1)`, with the worst outcome // being that an adversary may create or overwrite arbitrary files in the filesystem in case diff --git a/internal/gitaly/service/repository/backup_repository_test.go b/internal/gitaly/service/repository/backup_repository_test.go index e702b6391..5191d79d1 100644 --- a/internal/gitaly/service/repository/backup_repository_test.go +++ b/internal/gitaly/service/repository/backup_repository_test.go @@ -37,7 +37,7 @@ func TestServerBackupRepository(t *testing.T) { { desc: "success", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupSink(backupSink), testserver.WithBackupLocator(backupLocator), ) @@ -56,7 +56,7 @@ func TestServerBackupRepository(t *testing.T) { { desc: "missing backup ID", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupSink(backupSink), testserver.WithBackupLocator(backupLocator), ) @@ -76,7 +76,7 @@ func TestServerBackupRepository(t *testing.T) { { desc: "missing repository", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupSink(backupSink), testserver.WithBackupLocator(backupLocator), ) @@ -93,7 +93,7 @@ func TestServerBackupRepository(t *testing.T) { { desc: "repository with no branches", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupSink(backupSink), testserver.WithBackupLocator(backupLocator), ) @@ -111,7 +111,7 @@ func TestServerBackupRepository(t *testing.T) { { desc: "missing backup sink", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupLocator(backupLocator), ) @@ -129,7 +129,7 @@ func TestServerBackupRepository(t *testing.T) { { desc: "missing backup locator", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupSink(backupSink), ) diff --git a/internal/gitaly/service/repository/calculate_checksum_test.go b/internal/gitaly/service/repository/calculate_checksum_test.go index 54800825b..a6b5d7e4e 100644 --- a/internal/gitaly/service/repository/calculate_checksum_test.go +++ b/internal/gitaly/service/repository/calculate_checksum_test.go @@ -21,7 +21,7 @@ func TestCalculateChecksum(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) type setupData struct { request *gitalypb.CalculateChecksumRequest diff --git a/internal/gitaly/service/repository/config_test.go b/internal/gitaly/service/repository/config_test.go index 2d04b0f2e..0b0cfc3f3 100644 --- a/internal/gitaly/service/repository/config_test.go +++ b/internal/gitaly/service/repository/config_test.go @@ -19,7 +19,7 @@ import ( func TestGetConfig(t *testing.T) { t.Parallel() - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) ctx := testhelper.Context(t) 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 c9a8501a1..99fd42ea5 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 @@ -24,7 +24,7 @@ func TestCreateBundleFromRefList_success(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) // Create a work tree with a HEAD pointing to a commit that is missing. CreateBundle should // clean this up before creating the bundle. @@ -74,7 +74,7 @@ func TestCreateBundleFromRefList_missing_ref(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, repoPath := gittest.CreateRepository(t, ctx, cfg) commitOID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master")) @@ -113,7 +113,7 @@ func TestCreateBundleFromRefList_validations(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, _ := gittest.CreateRepository(t, ctx, cfg) testCases := []struct { diff --git a/internal/gitaly/service/repository/create_bundle_test.go b/internal/gitaly/service/repository/create_bundle_test.go index 0e9605ccc..97e5d3cff 100644 --- a/internal/gitaly/service/repository/create_bundle_test.go +++ b/internal/gitaly/service/repository/create_bundle_test.go @@ -22,7 +22,7 @@ func TestCreateBundle_successful(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, repoPath := gittest.CreateRepository(t, ctx, cfg) gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch)) @@ -59,7 +59,7 @@ func TestCreateBundle_successful(t *testing.T) { func TestCreateBundle_validations(t *testing.T) { t.Parallel() - _, client := setupRepositoryServiceWithoutRepo(t) + _, client := setupRepositoryService(t) for _, tc := range []struct { desc string diff --git a/internal/gitaly/service/repository/create_fork_test.go b/internal/gitaly/service/repository/create_fork_test.go index c45b68860..502a31f34 100644 --- a/internal/gitaly/service/repository/create_fork_test.go +++ b/internal/gitaly/service/repository/create_fork_test.go @@ -92,7 +92,7 @@ func TestCreateFork_refs(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepo, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) @@ -144,7 +144,7 @@ func TestCreateFork_refs(t *testing.T) { func TestCreateFork_fsck(t *testing.T) { t.Parallel() - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) ctx := testhelper.Context(t) ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) @@ -229,7 +229,7 @@ func TestCreateFork_targetExists(t *testing.T) { } { t.Run(tc.desc, func(t *testing.T) { ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) repo, _ := gittest.CreateRepository(t, ctx, cfg) @@ -258,7 +258,7 @@ func TestCreateFork_validate(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, cli := setupRepositoryServiceWithoutRepo(t) + cfg, cli := setupRepositoryService(t) srcRepo, _ := gittest.CreateRepository(t, ctx, cfg) // Praefect does not rewrite the SourceRepository storage name, confirm diff --git a/internal/gitaly/service/repository/create_repository_from_bundle_test.go b/internal/gitaly/service/repository/create_repository_from_bundle_test.go index f76137898..32c65c826 100644 --- a/internal/gitaly/service/repository/create_repository_from_bundle_test.go +++ b/internal/gitaly/service/repository/create_repository_from_bundle_test.go @@ -29,7 +29,7 @@ func TestCreateRepositoryFromBundle(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, repoClient := setupRepositoryServiceWithoutRepo(t) + cfg, repoClient := setupRepositoryService(t) type setupData struct { repoProto *gitalypb.Repository @@ -174,7 +174,7 @@ func TestCreateRepositoryFromBundle_transactional(t *testing.T) { ctx := testhelper.Context(t) txManager := transaction.NewTrackingManager() - cfg, client := setupRepositoryServiceWithoutRepo(t, testserver.WithTransactionManager(txManager)) + cfg, client := setupRepositoryService(t, testserver.WithTransactionManager(txManager)) repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg) diff --git a/internal/gitaly/service/repository/create_repository_from_snapshot_test.go b/internal/gitaly/service/repository/create_repository_from_snapshot_test.go index e25df4651..fa0c6b310 100644 --- a/internal/gitaly/service/repository/create_repository_from_snapshot_test.go +++ b/internal/gitaly/service/repository/create_repository_from_snapshot_test.go @@ -73,7 +73,7 @@ func TestCreateRepositoryFromSnapshot_success(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) _, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch(git.DefaultBranch)) @@ -119,7 +119,7 @@ func TestCreateRepositoryFromSnapshot_repositoryExists(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) // This creates the first repository on the server. As this test can run with Praefect in front of it, // we'll use the next replica path Praefect will assign in order to ensure this repository creation @@ -144,7 +144,7 @@ func TestCreateRepositoryFromSnapshot_invalidArguments(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) srv := httptest.NewServer(&tarTesthandler{secret: secret}) t.Cleanup(srv.Close) @@ -218,7 +218,7 @@ func TestCreateRepositoryFromSnapshot_malformedArchive(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) // Note that we are also writing a blob here that is 16kB in size. This is because there is a bug in // CreateRepositoryFromSnapshot that would cause it to succeed when a tiny archive gets truncated. Please refer @@ -258,7 +258,7 @@ func TestCreateRepositoryFromSnapshot_resolvedAddressSuccess(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) _, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) @@ -315,7 +315,7 @@ func TestServer_CreateRepositoryFromSnapshot_validate(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - _, client := setupRepositoryServiceWithoutRepo(t) + _, client := setupRepositoryService(t) 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 29e2e2534..b7573f0da 100644 --- a/internal/gitaly/service/repository/create_repository_from_url_test.go +++ b/internal/gitaly/service/repository/create_repository_from_url_test.go @@ -27,7 +27,7 @@ func TestCreateRepositoryFromURL_successful(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) gitCmdFactory := gittest.NewCommandFactory(t, cfg) _, repoPath := gittest.CreateRepository(t, ctx, cfg) @@ -67,7 +67,7 @@ func TestCreateRepositoryFromURL_successfulWithOptionalParameters(t *testing.T) t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) gitCmdFactory := gittest.NewCommandFactory(t, cfg) _, remoteRepoPath := gittest.CreateRepository(t, ctx, cfg) @@ -122,7 +122,7 @@ func TestCreateRepositoryFromURL_existingTarget(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.desc, func(t *testing.T) { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) importedRepo := &gitalypb.Repository{ RelativePath: storage.DeriveReplicaPath(1), @@ -153,7 +153,7 @@ func TestCreateRepositoryFromURL_redirect(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) importedRepo := &gitalypb.Repository{ RelativePath: "imports/test-repo-imported.git", @@ -182,7 +182,7 @@ func TestCreateRepositoryFromURL_fsck(t *testing.T) { ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) _, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) @@ -327,7 +327,7 @@ func TestServer_CloneFromURLCommand_withMirror(t *testing.T) { func TestServer_CloneFromURLCommand_validate(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) testCases := []struct { desc string diff --git a/internal/gitaly/service/repository/create_repository_test.go b/internal/gitaly/service/repository/create_repository_test.go index 00377b48e..81e8eadfb 100644 --- a/internal/gitaly/service/repository/create_repository_test.go +++ b/internal/gitaly/service/repository/create_repository_test.go @@ -47,7 +47,7 @@ func TestCreateRepository_successful(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo := &gitalypb.Repository{ StorageName: cfg.Storages[0].Name, @@ -82,7 +82,7 @@ func TestCreateRepository_successful(t *testing.T) { func TestCreateRepository_withDefaultBranch(t *testing.T) { t.Parallel() - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) ctx := testhelper.Context(t) for _, tc := range []struct { @@ -132,7 +132,7 @@ func TestCreateRepository_withDefaultBranch(t *testing.T) { func TestCreateRepository_withObjectFormat(t *testing.T) { t.Parallel() - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) ctx := testhelper.Context(t) gitCmdFactory := gittest.NewCommandFactory(t, cfg) @@ -197,7 +197,7 @@ func TestCreateRepository_invalidArguments(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) preexistingRepo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ // This creates the first repository on the server. As this test can run with @@ -249,7 +249,7 @@ func TestCreateRepository_transactional(t *testing.T) { ctx := testhelper.Context(t) txManager := transaction.NewTrackingManager() - cfg, client := setupRepositoryServiceWithoutRepo(t, testserver.WithTransactionManager(txManager)) + cfg, client := setupRepositoryService(t, testserver.WithTransactionManager(txManager)) ctx, err := txinfo.InjectTransaction(ctx, 1, "node", true) require.NoError(t, err) diff --git a/internal/gitaly/service/repository/fetch_bundle_test.go b/internal/gitaly/service/repository/fetch_bundle_test.go index ed3dc66e8..0ee12eadb 100644 --- a/internal/gitaly/service/repository/fetch_bundle_test.go +++ b/internal/gitaly/service/repository/fetch_bundle_test.go @@ -25,7 +25,7 @@ func TestServer_FetchBundle_success(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) _, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) main := gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("main")) @@ -73,7 +73,7 @@ func TestServer_FetchBundle_transaction(t *testing.T) { ctx := testhelper.Context(t) txManager := transaction.NewTrackingManager() - cfg, client := setupRepositoryServiceWithoutRepo(t, testserver.WithTransactionManager(txManager), testserver.WithDisablePraefect()) + cfg, client := setupRepositoryService(t, testserver.WithTransactionManager(txManager), testserver.WithDisablePraefect()) _, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) sourceCommitID := gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("main")) @@ -122,7 +122,7 @@ func TestServer_FetchBundle_transaction(t *testing.T) { func TestServer_FetchBundle_validation(t *testing.T) { t.Parallel() - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) ctx := testhelper.Context(t) for _, tc := range []struct { diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go index 1f3e96456..56f6c1f19 100644 --- a/internal/gitaly/service/repository/fetch_remote_test.go +++ b/internal/gitaly/service/repository/fetch_remote_test.go @@ -906,7 +906,7 @@ func TestFetchRemote(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { t.Parallel() - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) setupData := tc.setup(t, cfg) for _, run := range setupData.runs { diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go index 22f8ef245..2a9a8a115 100644 --- a/internal/gitaly/service/repository/fetch_test.go +++ b/internal/gitaly/service/repository/fetch_test.go @@ -37,7 +37,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "success", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) commitID := gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("master")) @@ -63,7 +63,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "success + same repository", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) commitID := gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("master")) @@ -88,7 +88,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to branch not found", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) gittest.WriteCommit(t, cfg, sourceRepoPath) @@ -110,7 +110,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to branch not found (same repo)", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) gittest.WriteCommit(t, cfg, sourceRepoPath) @@ -131,7 +131,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to no repository provided", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, _ := gittest.CreateRepository(t, ctx, cfg) @@ -150,7 +150,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to no source branch", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, _ := gittest.CreateRepository(t, ctx, cfg) repoProto, _ := gittest.CreateRepository(t, ctx, cfg) @@ -170,7 +170,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to blanks in source branch", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, _ := gittest.CreateRepository(t, ctx, cfg) repoProto, _ := gittest.CreateRepository(t, ctx, cfg) @@ -191,7 +191,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to source branch starting with -", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, _ := gittest.CreateRepository(t, ctx, cfg) repoProto, _ := gittest.CreateRepository(t, ctx, cfg) @@ -212,7 +212,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to source branch with :", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, _ := gittest.CreateRepository(t, ctx, cfg) repoProto, _ := gittest.CreateRepository(t, ctx, cfg) @@ -233,7 +233,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to source branch with NUL", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, _ := gittest.CreateRepository(t, ctx, cfg) repoProto, _ := gittest.CreateRepository(t, ctx, cfg) @@ -254,7 +254,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to no target ref", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("master")) @@ -275,7 +275,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to blanks in target ref", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("master")) @@ -297,7 +297,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to target ref starting with -", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("master")) @@ -319,7 +319,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to target ref with :", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("master")) @@ -341,7 +341,7 @@ func TestFetchSourceBranch(t *testing.T) { { desc: "failure due to target ref with NUL", setup: func(t *testing.T) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) sourceRepoProto, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg) gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("master")) diff --git a/internal/gitaly/service/repository/fsck_test.go b/internal/gitaly/service/repository/fsck_test.go index 1f69f4009..0d78d1327 100644 --- a/internal/gitaly/service/repository/fsck_test.go +++ b/internal/gitaly/service/repository/fsck_test.go @@ -19,7 +19,7 @@ func TestFsck(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) equalResponse := func(tb testing.TB, expected *gitalypb.FsckResponse) func(*gitalypb.FsckResponse) { return func(actual *gitalypb.FsckResponse) { testhelper.ProtoEqual(tb, expected, actual) } diff --git a/internal/gitaly/service/repository/fullpath_test.go b/internal/gitaly/service/repository/fullpath_test.go index 29c073a4d..b31a56f47 100644 --- a/internal/gitaly/service/repository/fullpath_test.go +++ b/internal/gitaly/service/repository/fullpath_test.go @@ -21,7 +21,7 @@ func TestSetFullPath(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) t.Run("missing repository", func(t *testing.T) { response, err := client.SetFullPath(ctx, &gitalypb.SetFullPathRequest{ @@ -144,7 +144,7 @@ func TestFullPath(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) t.Run("missing repository", func(t *testing.T) { response, err := client.FullPath(ctx, &gitalypb.FullPathRequest{ diff --git a/internal/gitaly/service/repository/get_custom_hooks_test.go b/internal/gitaly/service/repository/get_custom_hooks_test.go index 85fade108..6e329b001 100644 --- a/internal/gitaly/service/repository/get_custom_hooks_test.go +++ b/internal/gitaly/service/repository/get_custom_hooks_test.go @@ -56,7 +56,7 @@ func TestGetCustomHooks_successful(t *testing.T) { } { t.Run(tc.desc, func(t *testing.T) { ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, repoPath := gittest.CreateRepository(t, ctx, cfg) expectedTarResponse := []string{ @@ -123,7 +123,7 @@ func TestGetCustomHooks_symlink(t *testing.T) { } { t.Run(tc.desc, func(t *testing.T) { ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, repoPath := gittest.CreateRepository(t, ctx, cfg) linkTarget := "/var/empty" @@ -181,7 +181,7 @@ func TestGetCustomHooks_nonexistentHooks(t *testing.T) { } { t.Run(tc.desc, func(t *testing.T) { ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, _ := gittest.CreateRepository(t, ctx, cfg) buf, err := io.ReadAll(tc.streamReader(t, ctx, repo, client)) @@ -195,7 +195,7 @@ func TestGetCustomHooks_validate(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - _, client := setupRepositoryServiceWithoutRepo(t) + _, client := setupRepositoryService(t) for _, tc := range []struct { desc string @@ -221,7 +221,7 @@ func TestBackupCustomHooks_validate(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - _, client := setupRepositoryServiceWithoutRepo(t) + _, client := setupRepositoryService(t) for _, tc := range []struct { desc string diff --git a/internal/gitaly/service/repository/has_local_branches_test.go b/internal/gitaly/service/repository/has_local_branches_test.go index 513e478e9..b9eb49db6 100644 --- a/internal/gitaly/service/repository/has_local_branches_test.go +++ b/internal/gitaly/service/repository/has_local_branches_test.go @@ -15,7 +15,7 @@ func TestHasLocalBranches_successful(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) populatedRepo, populatedRepoPath := gittest.CreateRepository(t, ctx, cfg) gittest.WriteCommit(t, cfg, populatedRepoPath, gittest.WithBranch("main")) @@ -58,7 +58,7 @@ func TestHasLocalBranches_failure(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - _, client := setupRepositoryServiceWithoutRepo(t) + _, client := setupRepositoryService(t) for _, tc := range []struct { desc string diff --git a/internal/gitaly/service/repository/info_attributes_test.go b/internal/gitaly/service/repository/info_attributes_test.go index 3db6c8f59..a0e25f3a5 100644 --- a/internal/gitaly/service/repository/info_attributes_test.go +++ b/internal/gitaly/service/repository/info_attributes_test.go @@ -21,7 +21,7 @@ func TestGetInfoAttributesExisting(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, repoPath := gittest.CreateRepository(t, ctx, cfg) infoPath := filepath.Join(repoPath, "info") @@ -51,7 +51,7 @@ func TestGetInfoAttributesNonExisting(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, _ := gittest.CreateRepository(t, ctx, cfg) request := &gitalypb.GetInfoAttributesRequest{Repository: repo} @@ -68,7 +68,7 @@ func TestGetInfoAttributesNonExisting(t *testing.T) { func TestGetInfoAttributes_validate(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - _, client := setupRepositoryServiceWithoutRepo(t) + _, client := setupRepositoryService(t) response, err := client.GetInfoAttributes(ctx, &gitalypb.GetInfoAttributesRequest{Repository: nil}) require.NoError(t, err) _, err = response.Recv() diff --git a/internal/gitaly/service/repository/license_test.go b/internal/gitaly/service/repository/license_test.go index 6ec655d99..0346b26ed 100644 --- a/internal/gitaly/service/repository/license_test.go +++ b/internal/gitaly/service/repository/license_test.go @@ -42,7 +42,7 @@ SOFTWARE.` func TestFindLicense_successful(t *testing.T) { t.Parallel() - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) ctx := testhelper.Context(t) for _, tc := range []struct { @@ -254,7 +254,7 @@ func TestFindLicense_successful(t *testing.T) { func TestFindLicense_emptyRepo(t *testing.T) { t.Parallel() - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) ctx := testhelper.Context(t) repo, _ := gittest.CreateRepository(t, ctx, cfg) diff --git a/internal/gitaly/service/repository/merge_base_test.go b/internal/gitaly/service/repository/merge_base_test.go index e8ec0299c..da0d2061f 100644 --- a/internal/gitaly/service/repository/merge_base_test.go +++ b/internal/gitaly/service/repository/merge_base_test.go @@ -14,7 +14,7 @@ func TestFindMergeBase(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, repoPath := gittest.CreateRepository(t, ctx, cfg) diff --git a/internal/gitaly/service/repository/object_format_test.go b/internal/gitaly/service/repository/object_format_test.go index 77da79547..48032eadc 100644 --- a/internal/gitaly/service/repository/object_format_test.go +++ b/internal/gitaly/service/repository/object_format_test.go @@ -19,7 +19,7 @@ func TestObjectFormat(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) equalError := func(tb testing.TB, expected error) func(error) { return func(actual error) { diff --git a/internal/gitaly/service/repository/objects_size_test.go b/internal/gitaly/service/repository/objects_size_test.go index 7b69e6f45..8a23c2ec5 100644 --- a/internal/gitaly/service/repository/objects_size_test.go +++ b/internal/gitaly/service/repository/objects_size_test.go @@ -18,7 +18,7 @@ func TestObjectsSize(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) type setupData struct { requests []*gitalypb.ObjectsSizeRequest diff --git a/internal/gitaly/service/repository/optimize_test.go b/internal/gitaly/service/repository/optimize_test.go index 728fd472b..97e72da6a 100644 --- a/internal/gitaly/service/repository/optimize_test.go +++ b/internal/gitaly/service/repository/optimize_test.go @@ -29,7 +29,7 @@ func TestOptimizeRepository(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) t.Run("gitconfig credentials get pruned", func(t *testing.T) { t.Parallel() @@ -276,7 +276,7 @@ func TestOptimizeRepository_strategy(t *testing.T) { } ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t, testserver.WithHousekeepingManager(housekeepingManager)) + cfg, client := setupRepositoryService(t, testserver.WithHousekeepingManager(housekeepingManager)) repoProto, _ := gittest.CreateRepository(t, ctx, cfg) @@ -323,7 +323,7 @@ func TestOptimizeRepository_validation(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, _ := gittest.CreateRepository(t, ctx, cfg) for _, tc := range []struct { @@ -381,7 +381,7 @@ func TestOptimizeRepository_logStatistics(t *testing.T) { ctx := testhelper.Context(t) logger, hook := test.NewNullLogger() - cfg, client := setupRepositoryServiceWithoutRepo(t, testserver.WithLogger(logger)) + cfg, client := setupRepositoryService(t, testserver.WithLogger(logger)) repoProto, _ := gittest.CreateRepository(t, ctx, cfg) _, err := client.OptimizeRepository(ctx, &gitalypb.OptimizeRepositoryRequest{ diff --git a/internal/gitaly/service/repository/prune_unreachable_objects_test.go b/internal/gitaly/service/repository/prune_unreachable_objects_test.go index 74a36ec39..63125f9f1 100644 --- a/internal/gitaly/service/repository/prune_unreachable_objects_test.go +++ b/internal/gitaly/service/repository/prune_unreachable_objects_test.go @@ -21,7 +21,7 @@ func TestPruneUnreachableObjects(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) setObjectTime := func(t *testing.T, repoPath string, objectID git.ObjectID, when time.Time) { looseObjectPath := filepath.Join(repoPath, "objects", objectID.String()[:2], objectID.String()[2:]) diff --git a/internal/gitaly/service/repository/raw_changes.go b/internal/gitaly/service/repository/raw_changes.go index 8cfb7a02c..f97b45cda 100644 --- a/internal/gitaly/service/repository/raw_changes.go +++ b/internal/gitaly/service/repository/raw_changes.go @@ -18,11 +18,17 @@ import ( func (s *server) GetRawChanges(req *gitalypb.GetRawChangesRequest, stream gitalypb.RepositoryService_GetRawChangesServer) error { ctx := stream.Context() + repository := req.GetRepository() if err := s.locator.ValidateRepository(repository); err != nil { return structerr.NewInvalidArgument("%w", err) } + repo := s.localrepo(repository) + objectHash, err := repo.ObjectHash(ctx) + if err != nil { + return fmt.Errorf("detecting object hash: %w", err) + } objectInfoReader, cancel, err := s.catfileCache.ObjectInfoReader(stream.Context(), repo) if err != nil { @@ -30,25 +36,25 @@ func (s *server) GetRawChanges(req *gitalypb.GetRawChangesRequest, stream gitaly } defer cancel() - if err := validateRawChangesRequest(ctx, req, objectInfoReader); err != nil { + if err := validateRawChangesRequest(ctx, req, objectHash, objectInfoReader); err != nil { return structerr.NewInvalidArgument("%w", err) } - if err := s.getRawChanges(stream, repo, objectInfoReader, req.GetFromRevision(), req.GetToRevision()); err != nil { + if err := s.getRawChanges(stream, repo, objectHash, objectInfoReader, req.GetFromRevision(), req.GetToRevision()); err != nil { return structerr.NewInternal("%w", err) } return nil } -func validateRawChangesRequest(ctx context.Context, req *gitalypb.GetRawChangesRequest, objectInfoReader catfile.ObjectInfoReader) error { - if from := req.FromRevision; !git.ObjectHashSHA1.IsZeroOID(git.ObjectID(from)) { +func validateRawChangesRequest(ctx context.Context, req *gitalypb.GetRawChangesRequest, objectHash git.ObjectHash, objectInfoReader catfile.ObjectInfoReader) error { + if from := req.FromRevision; !objectHash.IsZeroOID(git.ObjectID(from)) { if _, err := objectInfoReader.Info(ctx, git.Revision(from)); err != nil { return fmt.Errorf("invalid 'from' revision: %q", from) } } - if to := req.ToRevision; !git.ObjectHashSHA1.IsZeroOID(git.ObjectID(to)) { + if to := req.ToRevision; !objectHash.IsZeroOID(git.ObjectID(to)) { if _, err := objectInfoReader.Info(ctx, git.Revision(to)); err != nil { return fmt.Errorf("invalid 'to' revision: %q", to) } @@ -57,13 +63,13 @@ func validateRawChangesRequest(ctx context.Context, req *gitalypb.GetRawChangesR return nil } -func (s *server) getRawChanges(stream gitalypb.RepositoryService_GetRawChangesServer, repo git.RepositoryExecutor, objectInfoReader catfile.ObjectInfoReader, from, to string) error { - if git.ObjectHashSHA1.IsZeroOID(git.ObjectID(to)) { +func (s *server) getRawChanges(stream gitalypb.RepositoryService_GetRawChangesServer, repo git.RepositoryExecutor, objectHash git.ObjectHash, objectInfoReader catfile.ObjectInfoReader, from, to string) error { + if objectHash.IsZeroOID(git.ObjectID(to)) { return nil } - if git.ObjectHashSHA1.IsZeroOID(git.ObjectID(from)) { - from = git.ObjectHashSHA1.EmptyTreeOID.String() + if objectHash.IsZeroOID(git.ObjectID(from)) { + from = objectHash.EmptyTreeOID.String() } ctx := stream.Context() diff --git a/internal/gitaly/service/repository/raw_changes_test.go b/internal/gitaly/service/repository/raw_changes_test.go index 05acb6ae0..4dab44ed6 100644 --- a/internal/gitaly/service/repository/raw_changes_test.go +++ b/internal/gitaly/service/repository/raw_changes_test.go @@ -1,15 +1,13 @@ -//go:build !gitaly_test_sha256 - package repository import ( + "errors" "fmt" "io" "testing" "unicode/utf8" "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/structerr" @@ -21,311 +19,332 @@ func TestGetRawChanges(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - _, repo, _, client := setupRepositoryService(t, ctx) + cfg, client := setupRepositoryService(t) + + type setupData struct { + request *gitalypb.GetRawChangesRequest + expectedErr error + expectedChanges []*gitalypb.GetRawChangesResponse_RawChange + } - testCases := []struct { - oldRev string - newRev string - changes []*gitalypb.GetRawChangesResponse_RawChange + for _, tc := range []struct { + desc string + setup func(t *testing.T) setupData }{ { - oldRev: "55bc176024cfa3baaceb71db584c7e5df900ea65", - newRev: "7975be0116940bf2ad4321f79d02a55c5f7779aa", - changes: []*gitalypb.GetRawChangesResponse_RawChange{ - { - BlobId: "c60514b6d3d6bf4bec1030f70026e34dfbd69ad5", - Size: 824, - NewPathBytes: []byte("README.md"), - OldPathBytes: []byte("README.md"), - Operation: gitalypb.GetRawChangesResponse_RawChange_MODIFIED, - OldMode: 0o100644, - NewMode: 0o100644, - }, - { - BlobId: "723c2c3f4c8a2a1e957f878c8813acfc08cda2b6", - Size: 1219696, - NewPathBytes: []byte("files/images/emoji.png"), - Operation: gitalypb.GetRawChangesResponse_RawChange_ADDED, - NewMode: 0o100644, - }, + desc: "missing from-revision", + setup: func(t *testing.T) setupData { + repo, _ := gittest.CreateRepository(t, ctx, cfg) + + return setupData{ + request: &gitalypb.GetRawChangesRequest{ + Repository: repo, + FromRevision: "", + ToRevision: gittest.DefaultObjectHash.HashData([]byte("irrelevant")).String(), + }, + expectedErr: structerr.NewInvalidArgument("invalid 'from' revision: %q", ""), + } }, }, { - oldRev: git.ObjectHashSHA1.ZeroOID.String(), - newRev: "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863", - changes: []*gitalypb.GetRawChangesResponse_RawChange{ - { - BlobId: "470ad2fcf1e33798f1afc5781d08e60c40f51e7a", - Size: 231, - NewPathBytes: []byte(".gitignore"), - Operation: gitalypb.GetRawChangesResponse_RawChange_ADDED, - NewMode: 0o100644, - }, - { - BlobId: "50b27c6518be44c42c4d87966ae2481ce895624c", - Size: 1075, - NewPathBytes: []byte("LICENSE"), - Operation: gitalypb.GetRawChangesResponse_RawChange_ADDED, - NewMode: 0o100644, - }, - { - BlobId: "faaf198af3a36dbf41961466703cc1d47c61d051", - Size: 55, - NewPathBytes: []byte("README.md"), - Operation: gitalypb.GetRawChangesResponse_RawChange_ADDED, - NewMode: 0o100644, - }, + desc: "missing repository", + setup: func(t *testing.T) setupData { + return setupData{ + request: &gitalypb.GetRawChangesRequest{}, + expectedErr: structerr.NewInvalidArgument("%w", storage.ErrRepositoryNotSet), + } }, }, { - oldRev: "6b8dc4a827797aa025ff6b8f425e583858a10d4f", - newRev: "06041ab2037429d243a38abb55957818dd9f948d", - changes: []*gitalypb.GetRawChangesResponse_RawChange{ - { - BlobId: "c84acd1ff0b844201312052f9bb3b7259eb2e177", - Size: 23, - NewPathBytes: []byte("files/executables/ls"), - OldPathBytes: []byte("files/executables/ls"), - Operation: gitalypb.GetRawChangesResponse_RawChange_MODIFIED, - OldMode: 0o100755, - NewMode: 0o100644, - }, + desc: "missing commit", + setup: func(t *testing.T) setupData { + repo, _ := gittest.CreateRepository(t, ctx, cfg) + missingCommitID := gittest.DefaultObjectHash.HashData([]byte("nonexistent commit")) + + return setupData{ + request: &gitalypb.GetRawChangesRequest{ + Repository: repo, + FromRevision: missingCommitID.String(), + ToRevision: missingCommitID.String(), + }, + expectedErr: structerr.NewInvalidArgument("invalid 'from' revision: %q", missingCommitID), + } }, }, - } - - for _, tc := range testCases { - t.Run(fmt.Sprintf("old:%s,new:%s", tc.oldRev, tc.newRev), func(t *testing.T) { - req := &gitalypb.GetRawChangesRequest{ - Repository: repo, - FromRevision: tc.oldRev, - ToRevision: tc.newRev, - } - - stream, err := client.GetRawChanges(ctx, req) - require.NoError(t, err) - - changes := collectChanges(t, stream) - require.Equal(t, tc.changes, changes) - }) - } -} - -func TestGetRawChangesSpecialCharacters(t *testing.T) { - t.Parallel() - // We know that 'git diff --raw' sometimes quotes "special characters" in - // paths, and that this can result in incorrect results from the - // GetRawChanges RPC, see - // https://gitlab.com/gitlab-org/gitaly/issues/1444. The definition of - // "special" is under core.quotePath in `git help config`. - // - // This test looks for a specific path known to contain special - // characters. - - ctx := testhelper.Context(t) - _, repo, _, client := setupRepositoryService(t, ctx) - - req := &gitalypb.GetRawChangesRequest{ - Repository: repo, - FromRevision: "cfe32cf61b73a0d5e9f13e774abde7ff789b1660", - ToRevision: "913c66a37b4a45b9769037c55c2d238bd0942d2e", - } - - stream, err := client.GetRawChanges(ctx, req) - require.NoError(t, err) - - changes := collectChanges(t, stream) - - nChangedFiles := 23 - require.Len(t, changes, nChangedFiles) - - specialFileIdx := 11 - require.Equal(t, "encoding/テスト.txt", string(changes[specialFileIdx].NewPathBytes)) -} - -func collectChanges(t *testing.T, stream gitalypb.RepositoryService_GetRawChangesClient) []*gitalypb.GetRawChangesResponse_RawChange { - t.Helper() - - var changes []*gitalypb.GetRawChangesResponse_RawChange - var err error - - for err == nil { - var msg *gitalypb.GetRawChangesResponse - msg, err = stream.Recv() - changes = append(changes, msg.GetRawChanges()...) - } - require.Equal(t, io.EOF, err) - - return changes -} - -func TestGetRawChangesFailures(t *testing.T) { - t.Parallel() - - ctx := testhelper.Context(t) - _, repo, _, client := setupRepositoryService(t, ctx) - - for _, tc := range []struct { - desc string - request *gitalypb.GetRawChangesRequest - expectedErr error - }{ { - desc: "missing from-revision", - request: &gitalypb.GetRawChangesRequest{ - Repository: repo, - FromRevision: "", - ToRevision: "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863", + desc: "simple change", + setup: func(t *testing.T) setupData { + repo, repoPath := gittest.CreateRepository(t, ctx, cfg) + + from := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "path", Mode: "100644", Content: "unchanged\n"}, + )) + + toData := []byte("changed\n") + toBlob := gittest.WriteBlob(t, cfg, repoPath, toData) + + to := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "path", Mode: "100644", OID: toBlob}, + )) + + return setupData{ + request: &gitalypb.GetRawChangesRequest{ + Repository: repo, + FromRevision: from.String(), + ToRevision: to.String(), + }, + expectedChanges: []*gitalypb.GetRawChangesResponse_RawChange{ + { + BlobId: toBlob.String(), + Size: int64(len(toData)), + OldPathBytes: []byte("path"), + NewPathBytes: []byte("path"), + Operation: gitalypb.GetRawChangesResponse_RawChange_MODIFIED, + OldMode: 0o100644, + NewMode: 0o100644, + }, + }, + } }, - expectedErr: structerr.NewInvalidArgument("invalid 'from' revision: %q", ""), }, { - desc: "missing repository", - request: &gitalypb.GetRawChangesRequest{ - FromRevision: "cfe32cf61b73a0d5e9f13e774abde7ff789b1660", - ToRevision: "913c66a37b4a45b9769037c55c2d238bd0942d2e", + desc: "comparison with zero OID", + setup: func(t *testing.T) setupData { + repo, repoPath := gittest.CreateRepository(t, ctx, cfg) + + blob := gittest.WriteBlob(t, cfg, repoPath, []byte("blob data\n")) + to := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "path", Mode: "100644", OID: blob}, + )) + + return setupData{ + request: &gitalypb.GetRawChangesRequest{ + Repository: repo, + FromRevision: gittest.DefaultObjectHash.ZeroOID.String(), + ToRevision: to.String(), + }, + expectedChanges: []*gitalypb.GetRawChangesResponse_RawChange{ + { + BlobId: blob.String(), + Size: 10, + NewPathBytes: []byte("path"), + NewMode: 0o100644, + Operation: gitalypb.GetRawChangesResponse_RawChange_ADDED, + }, + }, + } }, - expectedErr: structerr.NewInvalidArgument("%w", storage.ErrRepositoryNotSet), }, { - desc: "missing commit", - request: &gitalypb.GetRawChangesRequest{ - Repository: repo, - // A Gitaly commit, unresolvable in gitlab-test - FromRevision: "32800ed8206c0087f65e90a1a396b76d3c33f648", - ToRevision: "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863", + desc: "mode change", + setup: func(t *testing.T) setupData { + repo, repoPath := gittest.CreateRepository(t, ctx, cfg) + + blob := gittest.WriteBlob(t, cfg, repoPath, []byte("unmodified\n")) + from := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "path", Mode: "100644", OID: blob}, + )) + to := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "path", Mode: "100755", OID: blob}, + )) + + return setupData{ + request: &gitalypb.GetRawChangesRequest{ + Repository: repo, + FromRevision: from.String(), + ToRevision: to.String(), + }, + expectedChanges: []*gitalypb.GetRawChangesResponse_RawChange{ + { + BlobId: blob.String(), + Size: 11, + OldPathBytes: []byte("path"), + NewPathBytes: []byte("path"), + OldMode: 0o100644, + NewMode: 0o100755, + Operation: gitalypb.GetRawChangesResponse_RawChange_MODIFIED, + }, + }, + } + }, + }, + { + desc: "special characters in path", + setup: func(t *testing.T) setupData { + repo, repoPath := gittest.CreateRepository(t, ctx, cfg) + + // We know that 'git diff --raw' sometimes quotes "special characters" in paths, and + // that this can result in incorrect results from the GetRawChanges RPC, see + // https://gitlab.com/gitlab-org/gitaly/issues/1444. The definition of "special" is + // under core.quotePath in `git help config`. + // + // This test verifies that we correctly handle these special characters. + from := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "テスト.txt", Mode: "100644", Content: "unchanged\n"}, + )) + + toBlob := gittest.WriteBlob(t, cfg, repoPath, []byte("changed\n")) + to := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "テスト.txt", Mode: "100644", OID: toBlob}, + )) + + return setupData{ + request: &gitalypb.GetRawChangesRequest{ + Repository: repo, + FromRevision: from.String(), + ToRevision: to.String(), + }, + expectedChanges: []*gitalypb.GetRawChangesResponse_RawChange{ + { + BlobId: toBlob.String(), + Size: 8, + OldPathBytes: []byte("テスト.txt"), + NewPathBytes: []byte("テスト.txt"), + OldMode: 0o100644, + NewMode: 0o100644, + Operation: gitalypb.GetRawChangesResponse_RawChange_MODIFIED, + }, + }, + } + }, + }, + { + desc: "invalid UTF-8 in path", + setup: func(t *testing.T) setupData { + repo, repoPath := gittest.CreateRepository(t, ctx, cfg) + + nonUTF8Filename := "hello\x80world" + require.False(t, utf8.ValidString(nonUTF8Filename)) + + from := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: nonUTF8Filename, Mode: "100644", Content: "unchanged\n"}, + )) + toBlob := gittest.WriteBlob(t, cfg, repoPath, []byte("changed\n")) + to := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: nonUTF8Filename, Mode: "100644", OID: toBlob}, + )) + + return setupData{ + request: &gitalypb.GetRawChangesRequest{ + Repository: repo, + FromRevision: from.String(), + ToRevision: to.String(), + }, + expectedChanges: []*gitalypb.GetRawChangesResponse_RawChange{ + { + BlobId: toBlob.String(), + Size: 8, + OldPathBytes: []byte(nonUTF8Filename), + NewPathBytes: []byte(nonUTF8Filename), + OldMode: 0o100644, + NewMode: 0o100644, + Operation: gitalypb.GetRawChangesResponse_RawChange_MODIFIED, + }, + }, + } + }, + }, + { + desc: "many files", + setup: func(t *testing.T) setupData { + repo, repoPath := gittest.CreateRepository(t, ctx, cfg) + + fromBlob := gittest.WriteBlob(t, cfg, repoPath, []byte("from\n")) + toBlob := gittest.WriteBlob(t, cfg, repoPath, []byte("to\n")) + + fromTreeEntries := make([]gittest.TreeEntry, 0, 1024) + toTreeEntries := make([]gittest.TreeEntry, 0, 1024) + expectedChanges := make([]*gitalypb.GetRawChangesResponse_RawChange, 0, 1024) + for i := 0; i < 1024; i++ { + path := fmt.Sprintf("path-%4d", i) + + fromTreeEntries = append(fromTreeEntries, gittest.TreeEntry{Path: path, Mode: "100644", OID: fromBlob}) + toTreeEntries = append(toTreeEntries, gittest.TreeEntry{Path: path, Mode: "100644", OID: toBlob}) + expectedChanges = append(expectedChanges, &gitalypb.GetRawChangesResponse_RawChange{ + BlobId: toBlob.String(), + Size: 3, + OldPathBytes: []byte(path), + NewPathBytes: []byte(path), + OldMode: 0o100644, + NewMode: 0o100644, + Operation: gitalypb.GetRawChangesResponse_RawChange_MODIFIED, + }) + } + + from := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries(fromTreeEntries...)) + to := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries(toTreeEntries...)) + + return setupData{ + request: &gitalypb.GetRawChangesRequest{ + Repository: repo, + FromRevision: from.String(), + ToRevision: to.String(), + }, + expectedChanges: expectedChanges, + } + }, + }, + { + desc: "rename", + setup: func(t *testing.T) setupData { + repo, repoPath := gittest.CreateRepository(t, ctx, cfg) + + blob := gittest.WriteBlob(t, cfg, repoPath, []byte("blob that is to be renamed\n")) + from := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "from-path", Mode: "100644", OID: blob}, + )) + to := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "to-path", Mode: "100644", OID: blob}, + )) + + return setupData{ + request: &gitalypb.GetRawChangesRequest{ + Repository: repo, + FromRevision: from.String(), + ToRevision: to.String(), + }, + expectedChanges: []*gitalypb.GetRawChangesResponse_RawChange{ + { + BlobId: blob.String(), + Size: 27, + OldPathBytes: []byte("from-path"), + NewPathBytes: []byte("to-path"), + OldMode: 0o100644, + NewMode: 0o100644, + Operation: gitalypb.GetRawChangesResponse_RawChange_RENAMED, + }, + }, + } }, - expectedErr: structerr.NewInvalidArgument("invalid 'from' revision: %q", "32800ed8206c0087f65e90a1a396b76d3c33f648"), }, } { - t.Run(fmt.Sprintf(tc.desc), func(t *testing.T) { - stream, err := client.GetRawChanges(ctx, tc.request) - require.NoError(t, err) + tc := tc - for err == nil { - _, err = stream.Recv() - } - testhelper.RequireGrpcError(t, tc.expectedErr, err) - }) - } -} + t.Run(tc.desc, func(t *testing.T) { + t.Parallel() -func TestGetRawChangesManyFiles(t *testing.T) { - t.Parallel() - - ctx := testhelper.Context(t) - _, repo, _, client := setupRepositoryService(t, ctx) + setup := tc.setup(t) - initCommit := "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863" - req := &gitalypb.GetRawChangesRequest{ - Repository: repo, - FromRevision: initCommit, - ToRevision: "many_files", - } - - c, err := client.GetRawChanges(ctx, req) - require.NoError(t, err) - - changes := collectChanges(t, c) - - require.True(t, len(changes) >= 1041, "Changes has to contain at least 1041 changes") -} - -func TestGetRawChangesMappingOperations(t *testing.T) { - t.Parallel() - - ctx := testhelper.Context(t) - _, repo, _, client := setupRepositoryService(t, ctx) - - req := &gitalypb.GetRawChangesRequest{ - Repository: repo, - FromRevision: "1b12f15a11fc6e62177bef08f47bc7b5ce50b141", - ToRevision: "94bb47ca1297b7b3731ff2a36923640991e9236f", - } - - c, err := client.GetRawChanges(ctx, req) - require.NoError(t, err) - msg, err := c.Recv() - require.NoError(t, err) - - ops := []gitalypb.GetRawChangesResponse_RawChange_Operation{} - for _, change := range msg.GetRawChanges() { - ops = append(ops, change.GetOperation()) - } - - expected := []gitalypb.GetRawChangesResponse_RawChange_Operation{ - gitalypb.GetRawChangesResponse_RawChange_RENAMED, - gitalypb.GetRawChangesResponse_RawChange_MODIFIED, - gitalypb.GetRawChangesResponse_RawChange_ADDED, - } - - firstChange := &gitalypb.GetRawChangesResponse_RawChange{ - BlobId: "53855584db773c3df5b5f61f72974cb298822fbb", - Size: 22846, - NewPathBytes: []byte("CHANGELOG.md"), - OldPathBytes: []byte("CHANGELOG"), - Operation: gitalypb.GetRawChangesResponse_RawChange_RENAMED, - OldMode: 0o100644, - NewMode: 0o100644, - } + stream, err := client.GetRawChanges(ctx, setup.request) + require.NoError(t, err) - require.Equal(t, firstChange, msg.GetRawChanges()[0]) - require.EqualValues(t, expected, ops) -} + var changes []*gitalypb.GetRawChangesResponse_RawChange + for { + var response *gitalypb.GetRawChangesResponse + response, err = stream.Recv() + if err != nil { + if errors.Is(err, io.EOF) { + err = nil + } -func TestGetRawChangesInvalidUTF8Paths(t *testing.T) { - t.Parallel() + break + } - ctx := testhelper.Context(t) - cfg, repo, repoPath, client := setupRepositoryService(t, ctx) - - const ( - // These are arbitrary blobs known to exist in the test repository - blobID1 = "c60514b6d3d6bf4bec1030f70026e34dfbd69ad5" - blobID2 = "50b27c6518be44c42c4d87966ae2481ce895624c" - nonUTF8Filename = "hello\x80world" - ) - require.False(t, utf8.ValidString(nonUTF8Filename)) // sanity check - - fromCommitID := gittest.WriteCommit(t, cfg, repoPath, - gittest.WithTreeEntries(gittest.TreeEntry{ - OID: blobID1, Path: nonUTF8Filename, Mode: "100644", - }), - ) - toCommitID := gittest.WriteCommit(t, cfg, repoPath, - gittest.WithTreeEntries(gittest.TreeEntry{ - OID: blobID2, Path: nonUTF8Filename, Mode: "100644", - }), - ) - - req := &gitalypb.GetRawChangesRequest{ - Repository: repo, - FromRevision: fromCommitID.String(), - ToRevision: toCommitID.String(), - } - - c, err := client.GetRawChanges(ctx, req) - require.NoError(t, err) - - newPathFound := false - oldPathFound := false - for { - msg, err := c.Recv() - if err != nil { - require.Equal(t, io.EOF, err) - break - } - - for _, rawChange := range msg.GetRawChanges() { - if string(rawChange.GetOldPathBytes()) == nonUTF8Filename { - oldPathFound = true + changes = append(changes, response.GetRawChanges()...) } - if string(rawChange.GetNewPathBytes()) == nonUTF8Filename { - newPathFound = true - } - } + testhelper.RequireGrpcError(t, setup.expectedErr, err) + testhelper.ProtoEqual(t, setup.expectedChanges, changes) + }) } - - require.True(t, newPathFound && oldPathFound) } diff --git a/internal/gitaly/service/repository/remove_all_test.go b/internal/gitaly/service/repository/remove_all_test.go index fc44f6114..1a861bc84 100644 --- a/internal/gitaly/service/repository/remove_all_test.go +++ b/internal/gitaly/service/repository/remove_all_test.go @@ -12,7 +12,7 @@ import ( func TestRemoveAll(t *testing.T) { t.Parallel() - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) ctx := testhelper.Context(t) _, repo1Path := gittest.CreateRepository(t, ctx, cfg) diff --git a/internal/gitaly/service/repository/remove_test.go b/internal/gitaly/service/repository/remove_test.go index 7f8b7d9d4..b49ad7c4a 100644 --- a/internal/gitaly/service/repository/remove_test.go +++ b/internal/gitaly/service/repository/remove_test.go @@ -17,7 +17,7 @@ import ( func TestRemoveRepository(t *testing.T) { t.Parallel() - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) ctx := testhelper.Context(t) repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ @@ -38,7 +38,7 @@ func TestRemoveRepository_doesNotExist(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) _, err := client.RemoveRepository(ctx, &gitalypb.RemoveRepositoryRequest{ Repository: &gitalypb.Repository{StorageName: cfg.Storages[0].Name, RelativePath: "/does/not/exist"}, @@ -49,7 +49,7 @@ func TestRemoveRepository_doesNotExist(t *testing.T) { func TestRemoveRepository_validate(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - _, client := setupRepositoryServiceWithoutRepo(t) + _, client := setupRepositoryService(t) _, err := client.RemoveRepository(ctx, &gitalypb.RemoveRepositoryRequest{Repository: nil}) testhelper.RequireGrpcError(t, structerr.NewInvalidArgument("%w", storage.ErrRepositoryNotSet), err) } @@ -59,7 +59,7 @@ func TestRemoveRepository_locking(t *testing.T) { ctx := testhelper.Context(t) // Praefect does not acquire a lock on repository deletion so disable the test case for Praefect. - cfg, client := setupRepositoryServiceWithoutRepo(t, testserver.WithDisablePraefect()) + cfg, client := setupRepositoryService(t, testserver.WithDisablePraefect()) repo, repoPath := gittest.CreateRepository(t, ctx, cfg) // Simulate a concurrent RPC holding the repository lock. diff --git a/internal/gitaly/service/repository/rename_test.go b/internal/gitaly/service/repository/rename_test.go index cd08ae0e0..120ece26f 100644 --- a/internal/gitaly/service/repository/rename_test.go +++ b/internal/gitaly/service/repository/rename_test.go @@ -20,7 +20,7 @@ func TestRenameRepositorySuccess(t *testing.T) { ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) locator := config.NewLocator(cfg) originalRepo, originalPath := gittest.CreateRepository(t, ctx, cfg) commitID := gittest.WriteCommit(t, cfg, originalPath) @@ -66,7 +66,7 @@ func TestRenameRepositoryDestinationExists(t *testing.T) { ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) existingDestinationRepo, destinationRepoPath := gittest.CreateRepository(t, ctx, cfg) commitID := gittest.WriteCommit(t, cfg, destinationRepoPath) @@ -87,7 +87,7 @@ func TestRenameRepositoryInvalidRequest(t *testing.T) { ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, _ := gittest.CreateRepository(t, ctx, cfg) testCases := []struct { diff --git a/internal/gitaly/service/repository/repository_info_test.go b/internal/gitaly/service/repository/repository_info_test.go index 1d2f69bef..d5d7d1e21 100644 --- a/internal/gitaly/service/repository/repository_info_test.go +++ b/internal/gitaly/service/repository/repository_info_test.go @@ -22,7 +22,7 @@ func TestRepositoryInfo(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) writeFile := func(t *testing.T, byteCount int, pathComponents ...string) string { t.Helper() diff --git a/internal/gitaly/service/repository/restore_repository_test.go b/internal/gitaly/service/repository/restore_repository_test.go index df0043a69..4f1ae76c9 100644 --- a/internal/gitaly/service/repository/restore_repository_test.go +++ b/internal/gitaly/service/repository/restore_repository_test.go @@ -38,7 +38,7 @@ func TestRestoreRepository(t *testing.T) { { desc: "restore backup ID", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupSink(backupSink), testserver.WithBackupLocator(backupLocator), ) @@ -80,7 +80,7 @@ func TestRestoreRepository(t *testing.T) { { desc: "restore latest", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupSink(backupSink), testserver.WithBackupLocator(backupLocator), ) @@ -122,7 +122,7 @@ func TestRestoreRepository(t *testing.T) { { desc: "restore latest missing", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupSink(backupSink), testserver.WithBackupLocator(backupLocator), ) @@ -145,7 +145,7 @@ func TestRestoreRepository(t *testing.T) { { desc: "missing repository", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupSink(backupSink), testserver.WithBackupLocator(backupLocator), ) @@ -165,7 +165,7 @@ func TestRestoreRepository(t *testing.T) { { desc: "missing backup sink", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupLocator(backupLocator), ) @@ -184,7 +184,7 @@ func TestRestoreRepository(t *testing.T) { { desc: "missing backup locator", setup: func(t *testing.T, ctx context.Context, backupSink backup.Sink, backupLocator backup.Locator) setupData { - cfg, client := setupRepositoryServiceWithoutRepo(t, + cfg, client := setupRepositoryService(t, testserver.WithBackupSink(backupSink), ) diff --git a/internal/gitaly/service/repository/search_files_test.go b/internal/gitaly/service/repository/search_files_test.go index 247ccfb0c..d048120f9 100644 --- a/internal/gitaly/service/repository/search_files_test.go +++ b/internal/gitaly/service/repository/search_files_test.go @@ -18,7 +18,7 @@ func TestSearchFilesByContent(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg) @@ -209,7 +209,7 @@ func TestSearchFilesByName(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg) treeID := gittest.WriteTree(t, cfg, repoPath, []gittest.TreeEntry{ diff --git a/internal/gitaly/service/repository/set_custom_hooks_test.go b/internal/gitaly/service/repository/set_custom_hooks_test.go index 3823209e1..513a6f536 100644 --- a/internal/gitaly/service/repository/set_custom_hooks_test.go +++ b/internal/gitaly/service/repository/set_custom_hooks_test.go @@ -166,7 +166,7 @@ func TestSetCustomHooks_failedValidation(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - _, client := setupRepositoryServiceWithoutRepo(t) + _, client := setupRepositoryService(t) err := tc.streamSender(t, ctx, client) testhelper.RequireGrpcError(t, structerr.NewInvalidArgument("%w", storage.ErrRepositoryNotSet), err) @@ -236,7 +236,7 @@ func TestSetCustomHooks_corruptTar(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, _ := gittest.CreateRepository(t, ctx, cfg) writer, closeStream := tc.streamWriter(t, ctx, repo, client) diff --git a/internal/gitaly/service/repository/size_test.go b/internal/gitaly/service/repository/size_test.go index d2ada476c..88eebf13b 100644 --- a/internal/gitaly/service/repository/size_test.go +++ b/internal/gitaly/service/repository/size_test.go @@ -24,7 +24,7 @@ func TestRepositorySize_poolMember(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, repoPath := gittest.CreateRepository(t, ctx, cfg) @@ -52,7 +52,7 @@ func TestRepositorySize_normalRepository(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) // An empty repository should have a size of zero. This is not quite true as there are some data structures like // the gitconfig, but they do not exceed 1kB of data. @@ -76,7 +76,7 @@ func TestRepositorySize_failure(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - _, client := setupRepositoryServiceWithoutRepo(t) + _, client := setupRepositoryService(t) for _, tc := range []struct { description string @@ -100,7 +100,7 @@ func TestRepositorySize_failure(t *testing.T) { func BenchmarkRepositorySize(b *testing.B) { ctx := testhelper.Context(b) - cfg, client := setupRepositoryServiceWithoutRepo(b) + cfg, client := setupRepositoryService(b) for _, tc := range []struct { desc string @@ -142,7 +142,7 @@ func TestGetObjectDirectorySize_successful(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repo, repoPath := gittest.CreateRepository(t, ctx, cfg) repo.GitObjectDirectory = "objects/" @@ -159,7 +159,7 @@ func TestGetObjectDirectorySize_quarantine(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) locator := config.NewLocator(cfg) t.Run("quarantined repo", func(t *testing.T) { diff --git a/internal/gitaly/service/repository/snapshot_test.go b/internal/gitaly/service/repository/snapshot_test.go index 377ce4394..a051a9a77 100644 --- a/internal/gitaly/service/repository/snapshot_test.go +++ b/internal/gitaly/service/repository/snapshot_test.go @@ -25,7 +25,7 @@ func TestGetSnapshot(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) getSnapshot := func(tb testing.TB, ctx context.Context, client gitalypb.RepositoryServiceClient, req *gitalypb.GetSnapshotRequest) ([]byte, error) { stream, err := client.GetSnapshot(ctx, req) diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go index 98d65e99a..ec0bd90e5 100644 --- a/internal/gitaly/service/repository/testhelper_test.go +++ b/internal/gitaly/service/repository/testhelper_test.go @@ -7,7 +7,6 @@ import ( "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" gitalyauth "gitlab.com/gitlab-org/gitaly/v16/auth" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v16/internal/git/stats" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service" @@ -114,16 +113,7 @@ func runRepositoryService(tb testing.TB, cfg config.Cfg, opts ...testserver.Gita return newRepositoryClient(tb, cfg, serverSocketPath), serverSocketPath } -func setupRepositoryService(tb testing.TB, ctx context.Context, opts ...testserver.GitalyServerOpt) (config.Cfg, *gitalypb.Repository, string, gitalypb.RepositoryServiceClient) { - cfg, client := setupRepositoryServiceWithoutRepo(tb, opts...) - - repo, repoPath := gittest.CreateRepository(tb, ctx, cfg, gittest.CreateRepositoryConfig{ - Seed: gittest.SeedGitLabTest, - }) - return cfg, repo, repoPath, client -} - -func setupRepositoryServiceWithoutRepo(tb testing.TB, opts ...testserver.GitalyServerOpt) (config.Cfg, gitalypb.RepositoryServiceClient) { +func setupRepositoryService(tb testing.TB, opts ...testserver.GitalyServerOpt) (config.Cfg, gitalypb.RepositoryServiceClient) { cfg := testcfg.Build(tb) testcfg.BuildGitalyHooks(tb, cfg) diff --git a/internal/gitaly/service/repository/write_ref_test.go b/internal/gitaly/service/repository/write_ref_test.go index 3cc700afb..08b3782bf 100644 --- a/internal/gitaly/service/repository/write_ref_test.go +++ b/internal/gitaly/service/repository/write_ref_test.go @@ -25,7 +25,7 @@ func TestWriteRef(t *testing.T) { ctx := testhelper.Context(t) txManager := transaction.NewTrackingManager() - cfg, client := setupRepositoryServiceWithoutRepo(t, testserver.WithTransactionManager(txManager)) + cfg, client := setupRepositoryService(t, testserver.WithTransactionManager(txManager)) type setupData struct { request *gitalypb.WriteRefRequest @@ -377,7 +377,7 @@ func TestWriteRef_locked(t *testing.T) { t.Parallel() ctx := testhelper.Context(t) - cfg, client := setupRepositoryServiceWithoutRepo(t) + cfg, client := setupRepositoryService(t) repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg) repo := localrepo.NewTestRepo(t, cfg, repoProto) |