debian-mirror-gitlab/spec/lib/gitlab/ci/pipeline/chain/create_spec.rb

127 lines
2.8 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Ci::Pipeline::Chain::Create do
2020-04-08 14:13:33 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
2018-03-17 18:26:18 +05:30
let(:pipeline) do
2022-03-02 08:16:31 +05:30
build(:ci_empty_pipeline, project: project, ref: 'master', user: user)
2018-03-17 18:26:18 +05:30
end
let(:command) do
Gitlab::Ci::Pipeline::Chain::Command.new(
2018-05-09 12:01:36 +05:30
project: project, current_user: user)
2018-03-17 18:26:18 +05:30
end
let(:step) { described_class.new(pipeline, command) }
context 'when pipeline is ready to be saved' do
2018-05-09 12:01:36 +05:30
before do
2018-10-15 14:42:47 +05:30
pipeline.stages.build(name: 'test', position: 0, project: project)
2018-05-09 12:01:36 +05:30
step.perform!
end
2018-03-17 18:26:18 +05:30
it 'saves a pipeline' do
expect(pipeline).to be_persisted
end
it 'does not break the chain' do
expect(step.break?).to be false
end
it 'creates stages' do
expect(pipeline.reload.stages).to be_one
2018-05-09 12:01:36 +05:30
expect(pipeline.stages.first).to be_persisted
2018-03-17 18:26:18 +05:30
end
end
context 'when pipeline has validation errors' do
let(:pipeline) do
build(:ci_pipeline, project: project, ref: nil)
end
2018-05-09 12:01:36 +05:30
before do
step.perform!
end
2018-03-17 18:26:18 +05:30
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
2022-01-26 12:08:38 +05:30
context 'tags persistence' do
let(:stage) do
2022-03-02 08:16:31 +05:30
build(:ci_stage_entity, pipeline: pipeline, project: project)
2022-01-26 12:08:38 +05:30
end
let(:job) do
build(:ci_build, stage: stage, pipeline: pipeline, project: project)
end
let(:bridge) do
build(:ci_bridge, stage: stage, pipeline: pipeline, project: project)
end
before do
pipeline.stages = [stage]
stage.statuses = [job, bridge]
end
context 'without tags' do
it 'extracts an empty tag list' do
expect(CommitStatus)
.to receive(:bulk_insert_tags!)
2022-03-02 08:16:31 +05:30
.with([job])
2022-01-26 12:08:38 +05:30
.and_call_original
step.perform!
expect(job).to be_persisted
expect(job.tag_list).to eq([])
end
end
context 'with tags' do
before do
job.tag_list = %w[tag1 tag2]
end
it 'bulk inserts tags' do
expect(CommitStatus)
.to receive(:bulk_insert_tags!)
2022-03-02 08:16:31 +05:30
.with([job])
2022-01-26 12:08:38 +05:30
.and_call_original
step.perform!
expect(job).to be_persisted
2022-03-02 08:16:31 +05:30
expect(job.reload.tag_list).to match_array(%w[tag1 tag2])
2022-01-26 12:08:38 +05:30
end
end
context 'when the feature flag is disabled' do
before do
job.tag_list = %w[tag1 tag2]
stub_feature_flags(ci_bulk_insert_tags: false)
end
it 'follows the old code path' do
expect(CommitStatus).not_to receive(:bulk_insert_tags!)
step.perform!
expect(job).to be_persisted
expect(job.reload.tag_list).to match_array(%w[tag1 tag2])
end
end
end
2018-03-17 18:26:18 +05:30
end