diff options
Diffstat (limited to 'spec/workers/ci/pipeline_artifacts')
-rw-r--r-- | spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb | 32 | ||||
-rw-r--r-- | spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb | 36 |
2 files changed, 68 insertions, 0 deletions
diff --git a/spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb b/spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb new file mode 100644 index 00000000000..000eda055af --- /dev/null +++ b/spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Ci::PipelineArtifacts::CoverageReportWorker do + describe '#perform' do + subject { described_class.new.perform(pipeline_id) } + + context 'when pipeline exists' do + let(:pipeline) { create(:ci_pipeline) } + let(:pipeline_id) { pipeline.id } + + it 'calls pipeline report result service' do + expect_next_instance_of(::Ci::PipelineArtifacts::CoverageReportService) do |create_artifact_service| + expect(create_artifact_service).to receive(:execute) + end + + subject + end + end + + context 'when pipeline does not exist' do + let(:pipeline_id) { non_existing_record_id } + + it 'does not call pipeline create artifact service' do + expect(Ci::PipelineArtifacts::CoverageReportService).not_to receive(:execute) + + subject + end + end + end +end diff --git a/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb b/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb new file mode 100644 index 00000000000..9e9aa962b63 --- /dev/null +++ b/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::PipelineArtifacts::ExpireArtifactsWorker do + let(:worker) { described_class.new } + + describe '#perform' do + let_it_be(:pipeline_artifact) do + create(:ci_pipeline_artifact, expire_at: 1.week.ago) + end + + it 'executes a service' do + expect_next_instance_of(::Ci::PipelineArtifacts::DestroyExpiredArtifactsService) do |instance| + expect(instance).to receive(:execute) + end + + worker.perform + end + + include_examples 'an idempotent worker' do + subject do + perform_multiple(worker: worker) + end + + it 'removes the artifact only once' do + expect(worker).to receive(:log_extra_metadata_on_done).with(:destroyed_pipeline_artifacts_count, 1) + expect(worker).to receive(:log_extra_metadata_on_done).with(:destroyed_pipeline_artifacts_count, 0) + + subject + + expect { pipeline_artifact.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + end + end +end |