diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/services/projects/update_remote_mirror_service_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/services/projects/update_remote_mirror_service_spec.rb')
-rw-r--r-- | spec/services/projects/update_remote_mirror_service_spec.rb | 62 |
1 files changed, 9 insertions, 53 deletions
diff --git a/spec/services/projects/update_remote_mirror_service_spec.rb b/spec/services/projects/update_remote_mirror_service_spec.rb index f0a8074f46c..09244db8010 100644 --- a/spec/services/projects/update_remote_mirror_service_spec.rb +++ b/spec/services/projects/update_remote_mirror_service_spec.rb @@ -10,10 +10,6 @@ RSpec.describe Projects::UpdateRemoteMirrorService do subject(:service) { described_class.new(project, project.creator) } - before do - stub_feature_flags(gitaly_ruby_remote_branches_ls_remote: false) - end - describe '#execute' do subject(:execute!) { service.execute(remote_mirror, 0) } @@ -26,17 +22,14 @@ RSpec.describe Projects::UpdateRemoteMirrorService do end it 'ensures the remote exists' do - stub_fetch_remote(project, remote_name: remote_name, ssh_auth: remote_mirror) - expect(remote_mirror).to receive(:ensure_remote!) execute! end - it 'fetches the remote repository' do - expect(project.repository) - .to receive(:fetch_remote) - .with(remote_mirror.remote_name, no_tags: true, ssh_auth: remote_mirror) + it 'does not fetch the remote repository' do + # See https://gitlab.com/gitlab-org/gitaly/-/issues/2670 + expect(project.repository).not_to receive(:fetch_remote) execute! end @@ -48,8 +41,6 @@ RSpec.describe Projects::UpdateRemoteMirrorService do end it 'marks the mirror as successfully finished' do - stub_fetch_remote(project, remote_name: remote_name, ssh_auth: remote_mirror) - result = execute! expect(result[:status]).to eq(:success) @@ -57,7 +48,7 @@ RSpec.describe Projects::UpdateRemoteMirrorService do end it 'marks the mirror as failed and raises the error when an unexpected error occurs' do - allow(project.repository).to receive(:fetch_remote).and_raise('Badly broken') + allow(remote_mirror).to receive(:update_repository).and_raise('Badly broken') expect { execute! }.to raise_error(/Badly broken/) @@ -67,33 +58,30 @@ RSpec.describe Projects::UpdateRemoteMirrorService do context 'when the update fails because of a `Gitlab::Git::CommandError`' do before do - allow(project.repository).to receive(:fetch_remote).and_raise(Gitlab::Git::CommandError.new('fetch failed')) + allow(remote_mirror).to receive(:update_repository) + .and_raise(Gitlab::Git::CommandError.new('update failed')) end it 'wraps `Gitlab::Git::CommandError`s in a service error' do - expect(execute!).to eq(status: :error, message: 'fetch failed') + expect(execute!).to eq(status: :error, message: 'update failed') end it 'marks the mirror as to be retried' do execute! expect(remote_mirror).to be_to_retry - expect(remote_mirror.last_error).to include('fetch failed') + expect(remote_mirror.last_error).to include('update failed') end it "marks the mirror as failed after #{described_class::MAX_TRIES} tries" do service.execute(remote_mirror, described_class::MAX_TRIES) expect(remote_mirror).to be_failed - expect(remote_mirror.last_error).to include('fetch failed') + expect(remote_mirror.last_error).to include('update failed') end end context 'when there are divergent refs' do - before do - stub_fetch_remote(project, remote_name: remote_name, ssh_auth: remote_mirror) - end - it 'marks the mirror as failed and sets an error message' do response = double(divergent_refs: %w[refs/heads/master refs/heads/develop]) expect(remote_mirror).to receive(:update_repository).and_return(response) @@ -106,37 +94,5 @@ RSpec.describe Projects::UpdateRemoteMirrorService do expect(remote_mirror.last_error).to include("refs/heads/develop") end end - - # https://gitlab.com/gitlab-org/gitaly/-/issues/2670 - context 'when `gitaly_ruby_remote_branches_ls_remote` is enabled' do - before do - stub_feature_flags(gitaly_ruby_remote_branches_ls_remote: true) - end - - it 'does not perform a fetch' do - expect(project.repository).not_to receive(:fetch_remote) - - execute! - end - end - end - - def stub_fetch_remote(project, remote_name:, ssh_auth:) - allow(project.repository) - .to receive(:fetch_remote) - .with(remote_name, no_tags: true, ssh_auth: ssh_auth) { fetch_remote(project.repository, remote_name) } - end - - def fetch_remote(repository, remote_name) - local_branch_names(repository).each do |branch| - commit = repository.commit(branch) - repository.write_ref("refs/remotes/#{remote_name}/#{branch}", commit.id) if commit - end - end - - def local_branch_names(repository) - branch_names = repository.branches.map(&:name) - # we want the protected branch to be pushed first - branch_names.unshift(branch_names.delete('master')) end end |