Commit 954827d7 authored by Marius Bobin's avatar Marius Bobin

Extract shared examples out of specs

Extract shared examples out of specs
parent 5c48b88c
......@@ -22,18 +22,30 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
describe '#execute' do
subject(:execute) { described_class.new(pipeline).execute }
shared_examples 'available CI quota' do
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
end
shared_examples 'limit exceeded' do
it 'drops the job' do
execute
job.reload
expect(job).to be_failed
expect(job.failure_reason).to eq('ci_quota_exceeded')
end
end
context 'with public projects' do
before do
pipeline.project.update!(visibility_level: ::Gitlab::VisibilityLevel::PUBLIC)
end
context 'with available CI quota' do
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
end
it_behaves_like 'available CI quota'
context 'when the Ci quota is exceeded' do
context 'when the CI quota is exceeded' do
before do
allow(pipeline.project).to receive(:ci_minutes_quota)
.and_return(double('quota', minutes_used_up?: true))
......@@ -50,11 +62,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
pipeline.project.update!(visibility_level: ::Gitlab::VisibilityLevel::INTERNAL)
end
context 'with available CI quota' do
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
end
it_behaves_like 'available CI quota'
context 'when the Ci quota is exceeded' do
before do
......@@ -62,13 +70,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
.and_return(double('quota', minutes_used_up?: true))
end
it 'drops the job' do
execute
job.reload
expect(job).to be_failed
expect(job.failure_reason).to eq('ci_quota_exceeded')
end
it_behaves_like 'limit exceeded'
end
end
......@@ -77,11 +79,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
pipeline.project.update!(visibility_level: ::Gitlab::VisibilityLevel::PRIVATE)
end
context 'with available CI quota' do
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
end
it_behaves_like 'available CI quota'
context 'when the Ci quota is exceeded' do
before do
......@@ -89,13 +87,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
.and_return(double('quota', minutes_used_up?: true))
end
it 'drops the job' do
execute
job.reload
expect(job).to be_failed
expect(job.failure_reason).to eq('ci_quota_exceeded')
end
it_behaves_like 'limit exceeded'
end
end
end
......
......@@ -54,7 +54,7 @@ RSpec.describe Ci::ProcessPipelineService, '#execute' do
end
context 'with no runners' do
it 'creates a downstream cross-project pipeline' do
it 'creates a failed downstream cross-project pipeline' do
service.execute
Sidekiq::Worker.drain_all
......
......@@ -226,7 +226,7 @@ RSpec.describe Ci::CreatePipelineService do
end
context 'when there are no runners matching the builds' do
it 'creates a pipeline with build_a and test_b pending; deploy_b manual', :sidekiq_inline do
it 'creates a pipeline but all jobs failed', :sidekiq_inline do
processables = pipeline.processables
expect(pipeline).to be_created_successfully
......
......@@ -17,24 +17,26 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
describe '#execute' do
subject(:execute) { described_class.new(pipeline).execute }
shared_examples 'jobs allowed to run' do
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
end
context 'when the feature flag is disabled' do
before do
stub_feature_flags(ci_drop_new_builds_when_ci_quota_exceeded: false)
end
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
it_behaves_like 'jobs allowed to run'
end
context 'when the pipeline status is not created' do
context 'when the pipeline status is running' do
before do
pipeline.update!(status: :running)
end
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
it_behaves_like 'jobs allowed to run'
end
context 'when there are no runners available' do
......@@ -56,9 +58,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
create(:ci_runner, :online, runner_type: :project_type, projects: [project])
end
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
it_behaves_like 'jobs allowed to run'
end
context 'with group runners' do
......@@ -66,9 +66,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
create(:ci_runner, :online, runner_type: :group_type, groups: [group])
end
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
it_behaves_like 'jobs allowed to run'
end
context 'with instance runners' do
......@@ -76,9 +74,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
create(:ci_runner, :online, runner_type: :instance_type)
end
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
it_behaves_like 'jobs allowed to run'
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