diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-06 18:08:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-06 18:08:05 +0300 |
commit | f78257cbddd711e18cbce93ad740a4aa0acac347 (patch) | |
tree | 7f018abe3ce1c0010879cc480f348a35e616fabb /spec/services | |
parent | f500600a43b531e2e7a5858b74bd35312b02c349 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
3 files changed, 109 insertions, 27 deletions
diff --git a/spec/services/ci/create_pipeline_service/custom_config_content_spec.rb b/spec/services/ci/create_pipeline_service/custom_config_content_spec.rb index 2657f1d300a..112b19fcbc5 100644 --- a/spec/services/ci/create_pipeline_service/custom_config_content_spec.rb +++ b/spec/services/ci/create_pipeline_service/custom_config_content_spec.rb @@ -4,30 +4,77 @@ require 'spec_helper' describe Ci::CreatePipelineService do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:admin) } - let(:upstream_pipeline) { create(:ci_pipeline) } let(:ref) { 'refs/heads/master' } let(:service) { described_class.new(project, user, { ref: ref }) } + let(:upstream_pipeline) { create(:ci_pipeline, project: project) } + let(:bridge) { create(:ci_bridge, pipeline: upstream_pipeline) } + + subject { service.execute(:push, bridge: bridge) } + context 'custom config content' do let(:bridge) do create(:ci_bridge, status: 'running', pipeline: upstream_pipeline, project: upstream_pipeline.project).tap do |bridge| - allow(bridge).to receive(:yaml_for_downstream).and_return( - <<~YML - rspec: - script: rspec - custom: - script: custom - YML - ) + allow(bridge).to receive(:yaml_for_downstream).and_return(config_from_bridge) end end - subject { service.execute(:push, bridge: bridge) } + let(:config_from_bridge) do + <<~YML + rspec: + script: rspec + custom: + script: custom + YML + end + + before do + allow(bridge).to receive(:yaml_for_downstream).and_return config_from_bridge + end it 'creates a pipeline using the content passed in as param' do expect(subject).to be_persisted expect(subject.builds.map(&:name)).to eq %w[rspec custom] expect(subject.config_source).to eq 'bridge_source' end + + context 'when bridge includes yaml from artifact' do + # the generated.yml is available inside the ci_build_artifacts.zip associated + # to the generator_job + let(:config_from_bridge) do + <<~YML + include: + - artifact: generated.yml + job: generator + YML + end + + context 'when referenced job exists' do + let!(:generator_job) do + create(:ci_build, :artifacts, + project: project, + pipeline: upstream_pipeline, + name: 'generator') + end + + it 'created a pipeline using the content passed in as param and download the artifact' do + expect(subject).to be_persisted + expect(subject.builds.pluck(:name)).to eq %w[rspec time custom] + expect(subject.config_source).to eq 'bridge_source' + end + end + + context 'when referenced job does not exist' do + it 'creates an empty pipeline' do + expect(subject).to be_persisted + expect(subject).to be_failed + expect(subject.errors.full_messages) + .to contain_exactly( + 'Job `generator` not found in parent pipeline or does not have artifacts!') + expect(subject.builds.pluck(:name)).to be_empty + expect(subject.config_source).to eq 'bridge_source' + end + end + end end end diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb index 12c51d01d63..cbf7a135c41 100644 --- a/spec/services/projects/fork_service_spec.rb +++ b/spec/services/projects/fork_service_spec.rb @@ -315,6 +315,7 @@ describe Projects::ForkService do # Stub everything required to move a project to a Gitaly shard that does not exist stub_storage_settings('test_second_storage' => { 'path' => 'tmp/tests/second_storage' }) allow_any_instance_of(Gitlab::Git::Repository).to receive(:fetch_repository_as_mirror).and_return(true) + allow_any_instance_of(Gitlab::Git::Repository).to receive(:checksum).and_return(::Gitlab::Git::BLANK_SHA) Projects::UpdateRepositoryStorageService.new(project).execute('test_second_storage') fork_after_move = fork_project(project) diff --git a/spec/services/projects/update_repository_storage_service_spec.rb b/spec/services/projects/update_repository_storage_service_spec.rb index a0917f718e6..2e9a4626abb 100644 --- a/spec/services/projects/update_repository_storage_service_spec.rb +++ b/spec/services/projects/update_repository_storage_service_spec.rb @@ -16,6 +16,15 @@ describe Projects::UpdateRepositoryStorageService do context 'without wiki and design repository' do let(:project) { create(:project, :repository, repository_read_only: true, wiki_enabled: false) } + let!(:checksum) { project.repository.checksum } + let(:project_repository_double) { double(:repository) } + + before do + allow(Gitlab::Git::Repository).to receive(:new).and_call_original + allow(Gitlab::Git::Repository).to receive(:new) + .with('test_second_storage', project.repository.raw.relative_path, project.repository.gl_repository, project.repository.full_path) + .and_return(project_repository_double) + end context 'when the move succeeds' do it 'moves the repository to the new storage and unmarks the repository as read only' do @@ -23,10 +32,14 @@ describe Projects::UpdateRepositoryStorageService do project.repository.path_to_repo end - expect_any_instance_of(Gitlab::Git::Repository).to receive(:fetch_repository_as_mirror) + expect(project_repository_double).to receive(:fetch_repository_as_mirror) .with(project.repository.raw).and_return(true) + expect(project_repository_double).to receive(:checksum) + .and_return(checksum) + + result = subject.execute('test_second_storage') - subject.execute('test_second_storage') + expect(result[:status]).to eq(:success) expect(project).not_to be_repository_read_only expect(project.repository_storage).to eq('test_second_storage') expect(gitlab_shell.repository_exists?('default', old_path)).to be(false) @@ -44,16 +57,50 @@ describe Projects::UpdateRepositoryStorageService do context 'when the move fails' do it 'unmarks the repository as read-only without updating the repository storage' do - expect_any_instance_of(Gitlab::Git::Repository).to receive(:fetch_repository_as_mirror) + expect(project_repository_double).to receive(:fetch_repository_as_mirror) .with(project.repository.raw).and_return(false) expect(GitlabShellWorker).not_to receive(:perform_async) - subject.execute('test_second_storage') + result = subject.execute('test_second_storage') + expect(result[:status]).to eq(:error) expect(project).not_to be_repository_read_only expect(project.repository_storage).to eq('default') end end + + context 'when the checksum does not match' do + it 'unmarks the repository as read-only without updating the repository storage' do + expect(project_repository_double).to receive(:fetch_repository_as_mirror) + .with(project.repository.raw).and_return(true) + expect(project_repository_double).to receive(:checksum) + .and_return('not matching checksum') + expect(GitlabShellWorker).not_to receive(:perform_async) + + result = subject.execute('test_second_storage') + + expect(result[:status]).to eq(:error) + expect(project).not_to be_repository_read_only + expect(project.repository_storage).to eq('default') + end + end + + context 'when a object pool was joined' do + let!(:pool) { create(:pool_repository, :ready, source_project: project) } + + it 'leaves the pool' do + expect(project_repository_double).to receive(:fetch_repository_as_mirror) + .with(project.repository.raw).and_return(true) + expect(project_repository_double).to receive(:checksum) + .and_return(checksum) + + result = subject.execute('test_second_storage') + + expect(result[:status]).to eq(:success) + expect(project.repository_storage).to eq('test_second_storage') + expect(project.reload_pool_repository).to be_nil + end + end end context 'with wiki repository' do @@ -66,18 +113,5 @@ describe Projects::UpdateRepositoryStorageService do end end end - - context 'when a object pool was joined' do - let(:project) { create(:project, :repository, wiki_enabled: false, repository_read_only: true) } - let(:pool) { create(:pool_repository, :ready, source_project: project) } - - it 'leaves the pool' do - allow_any_instance_of(Gitlab::Git::Repository).to receive(:fetch_repository_as_mirror).and_return(true) - - subject.execute('test_second_storage') - - expect(project.reload_pool_repository).to be_nil - end - end end end |