diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-25 00:10:12 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-25 00:10:12 +0300 |
commit | 65aa9cb3b665f885b5c80b817d84af6076b35f26 (patch) | |
tree | 53f3396ed5ba8acc1fe8f2f12a8ecb6e7978ae58 /spec/lib | |
parent | 2ae564d6f59fc939bfdbb155d445efe97b34c1e1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/database/migrations/batched_background_migration_helpers_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/git/commit_spec.rb | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/git/diff_tree_spec.rb | 30 | ||||
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 26 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/commit_service_spec.rb | 38 |
5 files changed, 99 insertions, 11 deletions
diff --git a/spec/lib/gitlab/database/migrations/batched_background_migration_helpers_spec.rb b/spec/lib/gitlab/database/migrations/batched_background_migration_helpers_spec.rb index 82f77d2bb19..158497b1fef 100644 --- a/spec/lib/gitlab/database/migrations/batched_background_migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migrations/batched_background_migration_helpers_spec.rb @@ -473,7 +473,7 @@ RSpec.describe Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers d "\n\n" \ "For more information, check the documentation" \ "\n\n" \ - "\thttps://docs.gitlab.com/ee/user/admin_area/monitoring/background_migrations.html#database-migrations-failing-because-of-batched-background-migration-not-finished" + "\thttps://docs.gitlab.com/ee/update/background_migrations.html#database-migrations-failing-because-of-batched-background-migration-not-finished" end it 'does not raise error when migration exists and is marked as finished' do diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb index dd9f77f0211..3b1dbf7d602 100644 --- a/spec/lib/gitlab/git/commit_spec.rb +++ b/spec/lib/gitlab/git/commit_spec.rb @@ -3,15 +3,16 @@ require "spec_helper" RSpec.describe Gitlab::Git::Commit, feature_category: :source_code_management do - let(:repository) { create(:project, :repository).repository.raw } + let_it_be(:repository) { create(:project, :repository).repository.raw } let(:commit) { described_class.find(repository, SeedRepo::Commit::ID) } describe "Commit info from gitaly commit" do let(:subject) { (+"My commit").force_encoding('ASCII-8BIT') } let(:body) { subject + (+"My body").force_encoding('ASCII-8BIT') } let(:body_size) { body.length } - let(:gitaly_commit) { build(:gitaly_commit, subject: subject, body: body, body_size: body_size) } + let(:gitaly_commit) { build(:gitaly_commit, subject: subject, body: body, body_size: body_size, tree_id: tree_id) } let(:id) { gitaly_commit.id } + let(:tree_id) { 'd7f32d821c9cc7b1a9166ca7c4ba95b5c2d0d000' } let(:committer) { gitaly_commit.committer } let(:author) { gitaly_commit.author } let(:commit) { described_class.new(repository, gitaly_commit) } @@ -26,6 +27,7 @@ RSpec.describe Gitlab::Git::Commit, feature_category: :source_code_management do it { expect(commit.committer_name).to eq(committer.name) } it { expect(commit.committer_email).to eq(committer.email) } it { expect(commit.parent_ids).to eq(gitaly_commit.parent_ids) } + it { expect(commit.tree_id).to eq(tree_id) } context 'non-UTC dates' do let(:seconds) { Time.now.to_i } @@ -577,6 +579,14 @@ RSpec.describe Gitlab::Git::Commit, feature_category: :source_code_management do it { is_expected.to eq(sample_commit_hash[:message]) } end + + describe '#tree_id' do + subject { super().tree_id } + + it "doesn't return tree id for non-Gitaly commits" do + is_expected.to be_nil + end + end end describe '#stats' do diff --git a/spec/lib/gitlab/git/diff_tree_spec.rb b/spec/lib/gitlab/git/diff_tree_spec.rb new file mode 100644 index 00000000000..614a8f03dd8 --- /dev/null +++ b/spec/lib/gitlab/git/diff_tree_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe Gitlab::Git::DiffTree, feature_category: :source_code_management do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:repository) { project.repository } + + describe '.from_commit' do + subject(:diff_tree) { described_class.from_commit(commit) } + + context 'when commit is an initial commit' do + let(:commit) { repository.commit('1a0b36b3cdad1d2ee32457c102a8c0b7056fa863') } + + it 'returns the expected diff tree object' do + expect(diff_tree.left_tree_id).to eq(Gitlab::Git::EMPTY_TREE_ID) + expect(diff_tree.right_tree_id).to eq(commit.tree_id) + end + end + + context 'when commit is a regular commit' do + let(:commit) { repository.commit('60ecb67744cb56576c30214ff52294f8ce2def98') } + + it 'returns the expected diff tree object' do + expect(diff_tree.left_tree_id).to eq(commit.parent.tree_id) + expect(diff_tree.right_tree_id).to eq(commit.tree_id) + end + end + end +end diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 9c7f393490e..7ab56956068 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -1705,9 +1705,13 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen end describe '#find_changed_paths' do - let(:commit_1) { TestEnv::BRANCH_SHA['with-executables'] } - let(:commit_2) { TestEnv::BRANCH_SHA['master'] } - let(:commit_3) { '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9' } + let_it_be(:commit_1) { repository.commit(TestEnv::BRANCH_SHA['with-executables']) } + let_it_be(:commit_2) { repository.commit(TestEnv::BRANCH_SHA['master']) } + let_it_be(:commit_3) { repository.commit('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') } + + let_it_be(:initial_commit) { repository.commit('1a0b36b3cdad1d2ee32457c102a8c0b7056fa863') } + let_it_be(:diff_tree) { Gitlab::Git::DiffTree.from_commit(initial_commit) } + let(:commit_1_files) do [Gitlab::Git::ChangedPath.new(status: :ADDED, path: "files/executables/ls")] end @@ -1723,18 +1727,26 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen ] end + let(:diff_tree_files) do + [ + Gitlab::Git::ChangedPath.new(status: :ADDED, path: ".gitignore"), + Gitlab::Git::ChangedPath.new(status: :ADDED, path: "LICENSE"), + Gitlab::Git::ChangedPath.new(status: :ADDED, path: "README.md") + ] + end + it 'returns a list of paths' do - collection = repository.find_changed_paths([commit_1, commit_2, commit_3]) + collection = repository.find_changed_paths([commit_1, commit_2, commit_3, diff_tree]) expect(collection).to be_a(Enumerable) - expect(collection.as_json).to eq((commit_1_files + commit_2_files + commit_3_files).as_json) + expect(collection.as_json).to eq((commit_1_files + commit_2_files + commit_3_files + diff_tree_files).as_json) end - it 'returns no paths when SHAs are invalid' do + it 'returns only paths with valid SHAs' do collection = repository.find_changed_paths(['invalid', commit_1]) expect(collection).to be_a(Enumerable) - expect(collection.to_a).to be_empty + expect(collection.as_json).to eq(commit_1_files.as_json) end it 'returns a list of paths even when containing a blank ref' do diff --git a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb index fd66efe12c8..740073d5e4e 100644 --- a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb @@ -192,7 +192,9 @@ RSpec.describe Gitlab::GitalyClient::CommitService, feature_category: :gitaly do Gitaly::FindChangedPathsRequest.new(repository: repository_message, requests: requests, merge_commit_diff_mode: merge_commit_diff_mode) end - subject { described_class.new(repository).find_changed_paths(commits, merge_commit_diff_mode: merge_commit_diff_mode).as_json } + let(:treeish_objects) { repository.commits_by(oids: commits) } + + subject { described_class.new(repository).find_changed_paths(treeish_objects, merge_commit_diff_mode: merge_commit_diff_mode).as_json } before do allow(Gitaly::FindChangedPathsRequest).to receive(:new).and_call_original @@ -334,6 +336,40 @@ RSpec.describe Gitlab::GitalyClient::CommitService, feature_category: :gitaly do include_examples 'uses requests format' end end + + context 'when all requested objects are invalid' do + it 'does not send RPC request' do + expect_any_instance_of(Gitaly::DiffService::Stub).not_to receive(:find_changed_paths) + + returned_value = described_class.new(repository).find_changed_paths(%w[wrong values]) + + expect(returned_value).to eq([]) + end + end + + context 'when commit has an empty SHA' do + let(:empty_commit) { build(:commit, project: project, sha: '0000000000000000000000000000000000000000') } + + it 'does not send RPC request' do + expect_any_instance_of(Gitaly::DiffService::Stub).not_to receive(:find_changed_paths) + + returned_value = described_class.new(repository).find_changed_paths([empty_commit]) + + expect(returned_value).to eq([]) + end + end + + context 'when commit sha is not set' do + let(:empty_commit) { build(:commit, project: project, sha: nil) } + + it 'does not send RPC request' do + expect_any_instance_of(Gitaly::DiffService::Stub).not_to receive(:find_changed_paths) + + returned_value = described_class.new(repository).find_changed_paths([empty_commit]) + + expect(returned_value).to eq([]) + end + end end describe '#tree_entries' do |