Commit 0e22b50d authored by Shinya Maeda's avatar Shinya Maeda

Add spec for variables expression

parent 59e1e971
...@@ -37,23 +37,21 @@ describe Gitlab::Ci::Pipeline::Chain::Create do ...@@ -37,23 +37,21 @@ describe Gitlab::Ci::Pipeline::Chain::Create do
end end
context 'when pipeline has validation errors' do context 'when pipeline has validation errors' do
context 'when ref is nil' do let(:pipeline) do
let(:pipeline) do build(:ci_pipeline, project: project, ref: nil)
build(:ci_pipeline, project: project, ref: nil) end
end
before do
before do step.perform!
step.perform! end
end
it 'breaks the chain' do
it 'breaks the chain' do expect(step.break?).to be true
expect(step.break?).to be true end
end
it 'appends validation error' do
it 'appends validation error' do expect(pipeline.errors.to_a)
expect(pipeline.errors.to_a) .to include /Failed to persist the pipeline/
.to include /Failed to persist the pipeline/
end
end end
end end
end end
...@@ -42,6 +42,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ...@@ -42,6 +42,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
it 'correctly assigns user' do it 'correctly assigns user' do
expect(pipeline.builds).to all(have_attributes(user: user)) expect(pipeline.builds).to all(have_attributes(user: user))
end end
it 'has pipeline iid' do
expect(pipeline.iid).to be > 0
end
end end
context 'when pipeline is empty' do context 'when pipeline is empty' do
...@@ -68,6 +72,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ...@@ -68,6 +72,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect(pipeline.errors.to_a) expect(pipeline.errors.to_a)
.to include 'No stages / jobs for this pipeline.' .to include 'No stages / jobs for this pipeline.'
end end
it 'wastes pipeline iid' do
expect(InternalId.ci_pipelines.where(project_id: project.id).last.last_value).to be > 0
end
end end
context 'when pipeline has validation errors' do context 'when pipeline has validation errors' do
...@@ -87,6 +95,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ...@@ -87,6 +95,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect(pipeline.errors.to_a) expect(pipeline.errors.to_a)
.to include 'Failed to build the pipeline!' .to include 'Failed to build the pipeline!'
end end
it 'wastes pipeline iid' do
expect(InternalId.ci_pipelines.where(project_id: project.id).last.last_value).to be > 0
end
end end
context 'when there is a seed blocks present' do context 'when there is a seed blocks present' do
...@@ -111,6 +123,12 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ...@@ -111,6 +123,12 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect(pipeline.variables.first.key).to eq 'VAR' expect(pipeline.variables.first.key).to eq 'VAR'
expect(pipeline.variables.first.value).to eq '123' expect(pipeline.variables.first.value).to eq '123'
end end
it 'has pipeline iid' do
step.perform!
expect(pipeline.iid).to be > 0
end
end end
context 'when seeds block tries to persist some resources' do context 'when seeds block tries to persist some resources' do
...@@ -121,6 +139,12 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ...@@ -121,6 +139,12 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
it 'raises exception' do it 'raises exception' do
expect { step.perform! }.to raise_error(ActiveRecord::RecordNotSaved) expect { step.perform! }.to raise_error(ActiveRecord::RecordNotSaved)
end end
it 'does not waste pipeline iid' do
step.perform rescue nil
expect(InternalId.ci_pipelines.where(project_id: project.id).exists?).to be_falsy
end
end end
end end
......
...@@ -397,6 +397,20 @@ describe Ci::Pipeline, :mailer do ...@@ -397,6 +397,20 @@ describe Ci::Pipeline, :mailer do
expect(seeds.size).to eq 1 expect(seeds.size).to eq 1
expect(seeds.dig(0, 0, :name)).to eq 'unit' expect(seeds.dig(0, 0, :name)).to eq 'unit'
end end
context "when pipeline iid is used for 'only' keyword" do
let(:config) do
{ rspec: { script: 'rspec', only: { variables: ['$CI_PIPELINE_IID == 2'] } },
prod: { script: 'cap prod', only: { variables: ['$CI_PIPELINE_IID == 1'] } } }
end
it 'returns stage seeds only when variables expression is truthy' do
seeds = pipeline.stage_seeds
expect(seeds.size).to eq 1
expect(seeds.dig(0, 0, :name)).to eq 'prod'
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