Commit b5dfa745 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'improve-specs-for-ci-processbuildservice' into 'master'

Improve specs for Ci::ProcessBuildService

Closes #52279

See merge request gitlab-org/gitlab-ce!22254
parents 631f4e2f 995d2d13
...@@ -11,213 +11,135 @@ describe Ci::ProcessBuildService, '#execute' do ...@@ -11,213 +11,135 @@ describe Ci::ProcessBuildService, '#execute' do
project.add_maintainer(user) project.add_maintainer(user)
end end
shared_examples_for 'Enqueuing properly' do |valid_statuses_for_when| context 'when build has on_success option' do
valid_statuses_for_when.each do |status_for_prior_stages| let(:build) { create(:ci_build, :created, when: :on_success, user: user, project: project) }
context "when status for prior stages is #{status_for_prior_stages}" do
let(:current_status) { status_for_prior_stages }
%w[created skipped manual scheduled].each do |status| context 'when current status is success' do
context "when build status is #{status}" do let(:current_status) { 'success' }
let(:build) { create(:ci_build, status.to_sym, when: when_option, user: user, project: project) }
it 'enqueues the build' do it 'changes the build status' do
expect { subject }.to change { build.status }.to('pending') expect { subject }.to change { build.status }.to('pending')
end end
end end
end
%w[pending running success failed canceled].each do |status| context 'when current status is failed' do
context "when build status is #{status}" do let(:current_status) { 'failed' }
let(:build) { create(:ci_build, status.to_sym, when: when_option, user: user, project: project) }
it 'does not change the build status' do it 'does not change the build status' do
expect { subject }.not_to change { build.status } expect { subject }.to change { build.status }.to('skipped')
end
end
end end
end end
end end
(HasStatus::AVAILABLE_STATUSES - valid_statuses_for_when).each do |status_for_prior_stages| context 'when build has on_failure option' do
let(:current_status) { status_for_prior_stages } let(:build) { create(:ci_build, :created, when: :on_failure, user: user, project: project) }
context "when status for prior stages is #{status_for_prior_stages}" do context 'when current status is success' do
%w[created pending].each do |status| let(:current_status) { 'success' }
context "when build status is #{status}" do
let(:build) { create(:ci_build, status.to_sym, when: when_option, user: user, project: project) }
it 'skips the build' do it 'changes the build status' do
expect { subject }.to change { build.status }.to('skipped') expect { subject }.to change { build.status }.to('skipped')
end end
end end
end
(HasStatus::AVAILABLE_STATUSES - %w[created pending]).each do |status| context 'when current status is failed' do
context "when build status is #{status}" do let(:current_status) { 'failed' }
let(:build) { create(:ci_build, status.to_sym, when: when_option, user: user, project: project) }
it 'does not change build status' do it 'does not change the build status' do
expect { subject }.not_to change { build.status } expect { subject }.to change { build.status }.to('pending')
end
end
end
end end
end end
end end
shared_examples_for 'Actionizing properly' do |valid_statuses_for_when| context 'when build has always option' do
valid_statuses_for_when.each do |status_for_prior_stages| let(:build) { create(:ci_build, :created, when: :always, user: user, project: project) }
context "when status for prior stages is #{status_for_prior_stages}" do
let(:current_status) { status_for_prior_stages }
%w[created].each do |status| context 'when current status is success' do
context "when build status is #{status}" do let(:current_status) { 'success' }
let(:build) { create(:ci_build, status.to_sym, :actionable, user: user, project: project) }
it 'enqueues the build' do it 'changes the build status' do
expect { subject }.to change { build.status }.to('manual') expect { subject }.to change { build.status }.to('pending')
end
end end
end end
%w[manual skipped pending running success failed canceled scheduled].each do |status| context 'when current status is failed' do
context "when build status is #{status}" do let(:current_status) { 'failed' }
let(:build) { create(:ci_build, status.to_sym, :actionable, user: user, project: project) }
it 'does not change the build status' do it 'does not change the build status' do
expect { subject }.not_to change { build.status } expect { subject }.to change { build.status }.to('pending')
end
end
end end
end end
end end
(HasStatus::AVAILABLE_STATUSES - valid_statuses_for_when).each do |status_for_prior_stages| context 'when build has manual option' do
let(:current_status) { status_for_prior_stages } let(:build) { create(:ci_build, :created, :actionable, user: user, project: project) }
context "when status for prior stages is #{status_for_prior_stages}" do context 'when current status is success' do
%w[created pending].each do |status| let(:current_status) { 'success' }
context "when build status is #{status}" do
let(:build) { create(:ci_build, status.to_sym, :actionable, user: user, project: project) }
it 'skips the build' do it 'changes the build status' do
expect { subject }.to change { build.status }.to('skipped') expect { subject }.to change { build.status }.to('manual')
end
end end
end end
(HasStatus::AVAILABLE_STATUSES - %w[created pending]).each do |status| context 'when current status is failed' do
context "when build status is #{status}" do let(:current_status) { 'failed' }
let(:build) { create(:ci_build, status.to_sym, :actionable, user: user, project: project) }
it 'does not change build status' do it 'does not change the build status' do
expect { subject }.not_to change { build.status } expect { subject }.to change { build.status }.to('skipped')
end
end
end
end end
end end
end end
shared_examples_for 'Scheduling properly' do |valid_statuses_for_when| context 'when build has delayed option' do
valid_statuses_for_when.each do |status_for_prior_stages| before do
context "when status for prior stages is #{status_for_prior_stages}" do allow(Ci::BuildScheduleWorker).to receive(:perform_at) { }
let(:current_status) { status_for_prior_stages }
%w[created].each do |status|
context "when build status is #{status}" do
let(:build) { create(:ci_build, status.to_sym, :schedulable, user: user, project: project) }
it 'enqueues the build' do
expect { subject }.to change { build.status }.to('scheduled')
end
end
end end
%w[manual skipped pending running success failed canceled scheduled].each do |status| let(:build) { create(:ci_build, :created, :schedulable, user: user, project: project) }
context "when build status is #{status}" do
let(:build) { create(:ci_build, status.to_sym, :schedulable, user: user, project: project) }
it 'does not change the build status' do context 'when ci_enable_scheduled_build is enabled' do
expect { subject }.not_to change { build.status } before do
end stub_feature_flags(ci_enable_scheduled_build: true)
end
end
end
end end
(HasStatus::AVAILABLE_STATUSES - valid_statuses_for_when).each do |status_for_prior_stages| context 'when current status is success' do
let(:current_status) { status_for_prior_stages } let(:current_status) { 'success' }
context "when status for prior stages is #{status_for_prior_stages}" do
%w[created pending].each do |status|
context "when build status is #{status}" do
let(:build) { create(:ci_build, status.to_sym, :schedulable, user: user, project: project) }
it 'skips the build' do it 'changes the build status' do
expect { subject }.to change { build.status }.to('skipped') expect { subject }.to change { build.status }.to('scheduled')
end
end end
end end
(HasStatus::AVAILABLE_STATUSES - %w[created pending]).each do |status| context 'when current status is failed' do
context "when build status is #{status}" do let(:current_status) { 'failed' }
let(:build) { create(:ci_build, status.to_sym, :schedulable, user: user, project: project) }
it 'does not change build status' do it 'does not change the build status' do
expect { subject }.not_to change { build.status } expect { subject }.to change { build.status }.to('skipped')
end
end
end
end
end
end end
context 'when build has on_success option' do
let(:when_option) { :on_success }
it_behaves_like 'Enqueuing properly', %w[success skipped]
end end
context 'when build has on_failure option' do
let(:when_option) { :on_failure }
it_behaves_like 'Enqueuing properly', %w[failed]
end end
context 'when build has always option' do context 'when ci_enable_scheduled_build is disabled' do
let(:when_option) { :always } before do
stub_feature_flags(ci_enable_scheduled_build: false)
it_behaves_like 'Enqueuing properly', %w[success failed skipped]
end end
context 'when build has manual option' do context 'when current status is success' do
let(:when_option) { :manual } let(:current_status) { 'success' }
it_behaves_like 'Actionizing properly', %w[success skipped] it 'changes the build status' do
expect { subject }.to change { build.status }.to('manual')
end end
context 'when build has delayed option' do
let(:when_option) { :delayed }
before do
allow(Ci::BuildScheduleWorker).to receive(:perform_at) { }
end end
context 'when ci_enable_scheduled_build is enabled' do context 'when current status is failed' do
before do let(:current_status) { 'failed' }
stub_feature_flags(ci_enable_scheduled_build: true)
end
it_behaves_like 'Scheduling properly', %w[success skipped] it 'does not change the build status' do
expect { subject }.to change { build.status }.to('skipped')
end end
context 'when ci_enable_scheduled_build is enabled' do
before do
stub_feature_flags(ci_enable_scheduled_build: false)
end end
it_behaves_like 'Actionizing properly', %w[success skipped]
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment