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
end
context 'when pipeline has validation errors' do
context 'when ref is nil' do
let(:pipeline) do
build(:ci_pipeline, project: project, ref: nil)
end
before do
step.perform!
end
it 'breaks the chain' do
expect(step.break?).to be true
end
it 'appends validation error' do
expect(pipeline.errors.to_a)
.to include /Failed to persist the pipeline/
end
let(:pipeline) do
build(:ci_pipeline, project: project, ref: nil)
end
before do
step.perform!
end
it 'breaks the chain' do
expect(step.break?).to be true
end
it 'appends validation error' do
expect(pipeline.errors.to_a)
.to include /Failed to persist the pipeline/
end
end
end
......@@ -42,6 +42,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
it 'correctly assigns user' do
expect(pipeline.builds).to all(have_attributes(user: user))
end
it 'has pipeline iid' do
expect(pipeline.iid).to be > 0
end
end
context 'when pipeline is empty' do
......@@ -68,6 +72,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect(pipeline.errors.to_a)
.to include 'No stages / jobs for this pipeline.'
end
it 'wastes pipeline iid' do
expect(InternalId.ci_pipelines.where(project_id: project.id).last.last_value).to be > 0
end
end
context 'when pipeline has validation errors' do
......@@ -87,6 +95,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect(pipeline.errors.to_a)
.to include 'Failed to build the pipeline!'
end
it 'wastes pipeline iid' do
expect(InternalId.ci_pipelines.where(project_id: project.id).last.last_value).to be > 0
end
end
context 'when there is a seed blocks present' do
......@@ -111,6 +123,12 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect(pipeline.variables.first.key).to eq 'VAR'
expect(pipeline.variables.first.value).to eq '123'
end
it 'has pipeline iid' do
step.perform!
expect(pipeline.iid).to be > 0
end
end
context 'when seeds block tries to persist some resources' do
......@@ -121,6 +139,12 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
it 'raises exception' do
expect { step.perform! }.to raise_error(ActiveRecord::RecordNotSaved)
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
......
......@@ -397,6 +397,20 @@ describe Ci::Pipeline, :mailer do
expect(seeds.size).to eq 1
expect(seeds.dig(0, 0, :name)).to eq 'unit'
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
......
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