diff options
Diffstat (limited to 'spec/services/ci/create_job_artifacts_service_spec.rb')
-rw-r--r-- | spec/services/ci/create_job_artifacts_service_spec.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/services/ci/create_job_artifacts_service_spec.rb b/spec/services/ci/create_job_artifacts_service_spec.rb index fe64a66f322..4d49923a184 100644 --- a/spec/services/ci/create_job_artifacts_service_spec.rb +++ b/spec/services/ci/create_job_artifacts_service_spec.rb @@ -30,6 +30,26 @@ describe Ci::CreateJobArtifactsService do describe '#execute' do subject { service.execute(job, artifacts_file, params, metadata_file: metadata_file) } + context 'locking' do + let(:old_job) { create(:ci_build, pipeline: create(:ci_pipeline, project: job.project, ref: job.ref)) } + let!(:latest_artifact) { create(:ci_job_artifact, job: old_job, locked: true) } + let!(:other_artifact) { create(:ci_job_artifact, locked: true) } + + it 'locks the new artifact' do + subject + + expect(Ci::JobArtifact.last).to have_attributes(locked: true) + end + + it 'unlocks all other artifacts for the same ref' do + expect { subject }.to change { latest_artifact.reload.locked }.from(true).to(false) + end + + it 'does not unlock artifacts for other refs' do + expect { subject }.not_to change { other_artifact.reload.locked }.from(true) + end + end + context 'when artifacts file is uploaded' do it 'saves artifact for the given type' do expect { subject }.to change { Ci::JobArtifact.count }.by(1) @@ -157,6 +177,53 @@ describe Ci::CreateJobArtifactsService do end end + context 'when artifact type is cluster_applications' do + let(:artifacts_file) do + file_to_upload('spec/fixtures/helm/helm_list_v2_prometheus_missing.json.gz', sha256: artifacts_sha256) + end + + let(:params) do + { + 'artifact_type' => 'cluster_applications', + 'artifact_format' => 'gzip' + } + end + + it 'calls cluster applications parse service' do + expect_next_instance_of(Clusters::ParseClusterApplicationsArtifactService) do |service| + expect(service).to receive(:execute).once.and_call_original + end + + subject + end + + context 'when there is a deployment cluster' do + let(:user) { project.owner } + + before do + job.update!(user: user) + end + + it 'calls cluster applications parse service with job and job user', :aggregate_failures do + expect(Clusters::ParseClusterApplicationsArtifactService).to receive(:new).with(job, user).and_call_original + + subject + end + end + + context 'when ci_synchronous_artifact_parsing feature flag is disabled' do + before do + stub_feature_flags(ci_synchronous_artifact_parsing: false) + end + + it 'does not call parse service' do + expect(Clusters::ParseClusterApplicationsArtifactService).not_to receive(:new) + + expect(subject[:status]).to eq(:success) + end + end + end + shared_examples 'rescues object storage error' do |klass, message, expected_message| it "handles #{klass}" do allow_next_instance_of(JobArtifactUploader) do |uploader| |