summaryrefslogtreecommitdiff
path: root/spec/workers/ci
diff options
context:
space:
mode:
Diffstat (limited to 'spec/workers/ci')
-rw-r--r--spec/workers/ci/archive_traces_cron_worker_spec.rb2
-rw-r--r--spec/workers/ci/build_prepare_worker_spec.rb2
-rw-r--r--spec/workers/ci/build_report_result_worker_spec.rb2
-rw-r--r--spec/workers/ci/build_schedule_worker_spec.rb2
-rw-r--r--spec/workers/ci/create_cross_project_pipeline_worker_spec.rb2
-rw-r--r--spec/workers/ci/daily_build_group_report_results_worker_spec.rb2
-rw-r--r--spec/workers/ci/pipeline_bridge_status_worker_spec.rb2
-rw-r--r--spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb67
-rw-r--r--spec/workers/ci/ref_delete_unlock_artifacts_worker_spec.rb78
-rw-r--r--spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb2
10 files changed, 153 insertions, 8 deletions
diff --git a/spec/workers/ci/archive_traces_cron_worker_spec.rb b/spec/workers/ci/archive_traces_cron_worker_spec.rb
index 789e83783bb..14abe819587 100644
--- a/spec/workers/ci/archive_traces_cron_worker_spec.rb
+++ b/spec/workers/ci/archive_traces_cron_worker_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::ArchiveTracesCronWorker do
+RSpec.describe Ci::ArchiveTracesCronWorker do
subject { described_class.new.perform }
let(:finished_at) { 1.day.ago }
diff --git a/spec/workers/ci/build_prepare_worker_spec.rb b/spec/workers/ci/build_prepare_worker_spec.rb
index 9f76696ee66..b2c74a920ea 100644
--- a/spec/workers/ci/build_prepare_worker_spec.rb
+++ b/spec/workers/ci/build_prepare_worker_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::BuildPrepareWorker do
+RSpec.describe Ci::BuildPrepareWorker do
subject { described_class.new.perform(build_id) }
context 'build exists' do
diff --git a/spec/workers/ci/build_report_result_worker_spec.rb b/spec/workers/ci/build_report_result_worker_spec.rb
index 290a98366b4..aedfa70c8b8 100644
--- a/spec/workers/ci/build_report_result_worker_spec.rb
+++ b/spec/workers/ci/build_report_result_worker_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::BuildReportResultWorker do
+RSpec.describe Ci::BuildReportResultWorker do
subject { described_class.new.perform(build_id) }
context 'when build exists' do
diff --git a/spec/workers/ci/build_schedule_worker_spec.rb b/spec/workers/ci/build_schedule_worker_spec.rb
index 647f9763fed..f8b4efc562b 100644
--- a/spec/workers/ci/build_schedule_worker_spec.rb
+++ b/spec/workers/ci/build_schedule_worker_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::BuildScheduleWorker do
+RSpec.describe Ci::BuildScheduleWorker do
subject { described_class.new.perform(build.id) }
context 'when build is found' do
diff --git a/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb b/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb
index 492f5e812ee..95dcf5624cc 100644
--- a/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb
+++ b/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::CreateCrossProjectPipelineWorker do
+RSpec.describe Ci::CreateCrossProjectPipelineWorker do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
diff --git a/spec/workers/ci/daily_build_group_report_results_worker_spec.rb b/spec/workers/ci/daily_build_group_report_results_worker_spec.rb
index d9706982a62..e13c6311e46 100644
--- a/spec/workers/ci/daily_build_group_report_results_worker_spec.rb
+++ b/spec/workers/ci/daily_build_group_report_results_worker_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::DailyBuildGroupReportResultsWorker do
+RSpec.describe Ci::DailyBuildGroupReportResultsWorker do
describe '#perform' do
let!(:pipeline) { create(:ci_pipeline) }
diff --git a/spec/workers/ci/pipeline_bridge_status_worker_spec.rb b/spec/workers/ci/pipeline_bridge_status_worker_spec.rb
index a6129b2cf93..6ec5eb0e639 100644
--- a/spec/workers/ci/pipeline_bridge_status_worker_spec.rb
+++ b/spec/workers/ci/pipeline_bridge_status_worker_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::PipelineBridgeStatusWorker do
+RSpec.describe Ci::PipelineBridgeStatusWorker do
describe '#perform' do
subject { described_class.new.perform(pipeline_id) }
diff --git a/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb b/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb
new file mode 100644
index 00000000000..cb2cf58d50b
--- /dev/null
+++ b/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::PipelineSuccessUnlockArtifactsWorker do
+ describe '#perform' do
+ subject(:perform) { described_class.new.perform(pipeline_id) }
+
+ include_examples 'an idempotent worker' do
+ subject(:idempotent_perform) { perform_multiple(pipeline.id, exec_times: 2) }
+
+ let!(:older_pipeline) do
+ create(:ci_pipeline, :success, :with_job, locked: :artifacts_locked).tap do |pipeline|
+ create(:ci_job_artifact, job: pipeline.builds.first)
+ end
+ end
+
+ let!(:pipeline) do
+ create(:ci_pipeline, :success, :with_job, ref: older_pipeline.ref, tag: older_pipeline.tag, project: older_pipeline.project, locked: :unlocked).tap do |pipeline|
+ create(:ci_job_artifact, job: pipeline.builds.first)
+ end
+ end
+
+ it 'unlocks the artifacts from older pipelines' do
+ expect { idempotent_perform }.to change { older_pipeline.reload.locked }.from('artifacts_locked').to('unlocked')
+ end
+ end
+
+ context 'when pipeline exists' do
+ let(:pipeline) { create(:ci_pipeline, :success, :with_job) }
+ let(:pipeline_id) { pipeline.id }
+
+ context 'when pipeline has artifacts' do
+ before do
+ create(:ci_job_artifact, job: pipeline.builds.first)
+ end
+
+ it 'calls the service' do
+ service = spy(Ci::UnlockArtifactsService)
+ expect(Ci::UnlockArtifactsService).to receive(:new).and_return(service)
+
+ perform
+
+ expect(service).to have_received(:execute)
+ end
+ end
+
+ context 'when pipeline does not have artifacts' do
+ it 'does not call service' do
+ expect(Ci::UnlockArtifactsService).not_to receive(:new)
+
+ perform
+ end
+ end
+ end
+
+ context 'when pipeline does not exist' do
+ let(:pipeline_id) { non_existing_record_id }
+
+ it 'does not call service' do
+ expect(Ci::UnlockArtifactsService).not_to receive(:new)
+
+ perform
+ end
+ end
+ end
+end
diff --git a/spec/workers/ci/ref_delete_unlock_artifacts_worker_spec.rb b/spec/workers/ci/ref_delete_unlock_artifacts_worker_spec.rb
new file mode 100644
index 00000000000..d9f2dd326dd
--- /dev/null
+++ b/spec/workers/ci/ref_delete_unlock_artifacts_worker_spec.rb
@@ -0,0 +1,78 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::RefDeleteUnlockArtifactsWorker do
+ describe '#perform' do
+ subject(:perform) { described_class.new.perform(project_id, user_id, ref) }
+
+ let(:ref) { 'refs/heads/master' }
+
+ let(:project) { create(:project) }
+
+ include_examples 'an idempotent worker' do
+ subject(:idempotent_perform) { perform_multiple([project_id, user_id, ref], exec_times: 2) }
+
+ let(:project_id) { project.id }
+ let(:user_id) { project.creator.id }
+
+ let(:pipeline) { create(:ci_pipeline, ref: 'master', project: project, locked: :artifacts_locked) }
+
+ it 'unlocks the artifacts from older pipelines' do
+ expect { idempotent_perform }.to change { pipeline.reload.locked }.from('artifacts_locked').to('unlocked')
+ end
+ end
+
+ context 'when project exists' do
+ let(:project_id) { project.id }
+
+ context 'when user exists' do
+ let(:user_id) { project.creator.id }
+
+ context 'when ci ref exists' do
+ before do
+ create(:ci_ref, ref_path: ref)
+ end
+
+ it 'calls the service' do
+ service = spy(Ci::UnlockArtifactsService)
+ expect(Ci::UnlockArtifactsService).to receive(:new).and_return(service)
+
+ perform
+
+ expect(service).to have_received(:execute)
+ end
+ end
+
+ context 'when ci ref does not exist' do
+ it 'does not call the service' do
+ expect(Ci::UnlockArtifactsService).not_to receive(:new)
+
+ perform
+ end
+ end
+ end
+
+ context 'when user does not exist' do
+ let(:user_id) { non_existing_record_id }
+
+ it 'does not call service' do
+ expect(Ci::UnlockArtifactsService).not_to receive(:new)
+
+ perform
+ end
+ end
+ end
+
+ context 'when project does not exist' do
+ let(:project_id) { non_existing_record_id }
+ let(:user_id) { project.creator.id }
+
+ it 'does not call service' do
+ expect(Ci::UnlockArtifactsService).not_to receive(:new)
+
+ perform
+ end
+ end
+ end
+end
diff --git a/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb b/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb
index 634d932121e..f9914a7cecb 100644
--- a/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb
+++ b/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::ResourceGroups::AssignResourceFromResourceGroupWorker do
+RSpec.describe Ci::ResourceGroups::AssignResourceFromResourceGroupWorker do
let(:worker) { described_class.new }
describe '#perform' do