Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/releases/create_service_spec.rb')
-rw-r--r--spec/services/releases/create_service_spec.rb177
1 files changed, 177 insertions, 0 deletions
diff --git a/spec/services/releases/create_service_spec.rb b/spec/services/releases/create_service_spec.rb
index d0859500440..4e3d9d5f108 100644
--- a/spec/services/releases/create_service_spec.rb
+++ b/spec/services/releases/create_service_spec.rb
@@ -186,4 +186,181 @@ describe Releases::CreateService do
end
end
end
+
+ context 'Evidence collection' do
+ let(:sha) { project.repository.commit('master').sha }
+ let(:params) do
+ {
+ name: 'New release',
+ ref: 'master',
+ tag: 'v0.1',
+ description: 'Super nice release',
+ released_at: released_at
+ }.compact
+ end
+ let(:last_release) { project.releases.last }
+
+ around do |example|
+ Timecop.freeze { example.run }
+ end
+
+ subject { service.execute }
+
+ context 'historical release' do
+ let(:released_at) { 3.weeks.ago }
+
+ it 'does not execute CreateEvidenceWorker' do
+ expect { subject }.not_to change(CreateEvidenceWorker.jobs, :size)
+ end
+
+ it 'does not create an Evidence object', :sidekiq_inline do
+ expect { subject }.not_to change(Releases::Evidence, :count)
+ end
+
+ it 'is a historical release' do
+ subject
+
+ expect(last_release.historical_release?).to be_truthy
+ end
+
+ it 'is not an upcoming release' do
+ subject
+
+ expect(last_release.upcoming_release?).to be_falsy
+ end
+ end
+
+ shared_examples 'uses the right pipeline for evidence' do
+ it 'creates evidence without pipeline if it does not exist', :sidekiq_inline do
+ expect_next_instance_of(Releases::CreateEvidenceService, anything, pipeline: nil) do |service|
+ expect(service).to receive(:execute).and_call_original
+ end
+
+ expect { subject }.to change(Releases::Evidence, :count).by(1)
+ end
+
+ it 'uses the last pipeline for evidence', :sidekiq_inline do
+ create(:ci_empty_pipeline, sha: sha, project: project) # old pipeline
+ pipeline = create(:ci_empty_pipeline, sha: sha, project: project)
+
+ expect_next_instance_of(Releases::CreateEvidenceService, anything, pipeline: pipeline) do |service|
+ expect(service).to receive(:execute).and_call_original
+ end
+
+ expect { subject }.to change(Releases::Evidence, :count).by(1)
+ end
+
+ context 'when old evidence_pipeline is passed to service' do
+ let!(:old_pipeline) { create(:ci_empty_pipeline, sha: sha, project: project) }
+ let!(:new_pipeline) { create(:ci_empty_pipeline, sha: sha, project: project) }
+ let(:params) do
+ super().merge(
+ evidence_pipeline: old_pipeline
+ )
+ end
+
+ it 'uses the old pipeline for evidence', :sidekiq_inline do
+ expect_next_instance_of(Releases::CreateEvidenceService, anything, pipeline: old_pipeline) do |service|
+ expect(service).to receive(:execute).and_call_original
+ end
+
+ expect { subject }.to change(Releases::Evidence, :count).by(1)
+ end
+ end
+
+ it 'pipeline is still being used for evidence if new pipeline is being created for tag', :sidekiq_inline do
+ pipeline = create(:ci_empty_pipeline, sha: sha, project: project)
+
+ expect(project.repository).to receive(:add_tag).and_wrap_original do |m, *args|
+ create(:ci_empty_pipeline, sha: sha, project: project)
+ m.call(*args)
+ end
+
+ expect_next_instance_of(Releases::CreateEvidenceService, anything, pipeline: pipeline) do |service|
+ expect(service).to receive(:execute).and_call_original
+ end
+
+ expect { subject }.to change(Releases::Evidence, :count).by(1)
+ end
+
+ it 'uses the last pipeline for evidence when tag is already created', :sidekiq_inline do
+ Tags::CreateService.new(project, user).execute('v0.1', 'master', nil)
+
+ expect(project.repository.find_tag('v0.1')).to be_present
+
+ create(:ci_empty_pipeline, sha: sha, project: project) # old pipeline
+ pipeline = create(:ci_empty_pipeline, sha: sha, project: project)
+
+ expect_next_instance_of(Releases::CreateEvidenceService, anything, pipeline: pipeline) do |service|
+ expect(service).to receive(:execute).and_call_original
+ end
+
+ expect { subject }.to change(Releases::Evidence, :count).by(1)
+ end
+ end
+
+ context 'immediate release' do
+ let(:released_at) { nil }
+
+ it 'sets `released_at` to the current dttm' do
+ subject
+
+ expect(last_release.updated_at).to be_like_time(Time.current)
+ end
+
+ it 'queues CreateEvidenceWorker' do
+ expect { subject }.to change(CreateEvidenceWorker.jobs, :size).by(1)
+ end
+
+ it 'creates Evidence', :sidekiq_inline do
+ expect { subject }.to change(Releases::Evidence, :count).by(1)
+ end
+
+ it 'is not a historical release' do
+ subject
+
+ expect(last_release.historical_release?).to be_falsy
+ end
+
+ it 'is not an upcoming release' do
+ subject
+
+ expect(last_release.upcoming_release?).to be_falsy
+ end
+
+ include_examples 'uses the right pipeline for evidence'
+ end
+
+ context 'upcoming release' do
+ let(:released_at) { 1.day.from_now }
+
+ it 'queues CreateEvidenceWorker' do
+ expect { subject }.to change(CreateEvidenceWorker.jobs, :size).by(1)
+ end
+
+ it 'queues CreateEvidenceWorker at the released_at timestamp' do
+ subject
+
+ expect(CreateEvidenceWorker.jobs.last['at'].to_i).to eq(released_at.to_i)
+ end
+
+ it 'creates Evidence', :sidekiq_inline do
+ expect { subject }.to change(Releases::Evidence, :count).by(1)
+ end
+
+ it 'is not a historical release' do
+ subject
+
+ expect(last_release.historical_release?).to be_falsy
+ end
+
+ it 'is an upcoming release' do
+ subject
+
+ expect(last_release.upcoming_release?).to be_truthy
+ end
+
+ include_examples 'uses the right pipeline for evidence'
+ end
+ end
end