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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
2.4 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-08-13 15:12:31 +05:30
build(:ci_stage, pipeline: pipeline, project: project)
2022-01-26 12:08:38 +05:30
end
let(:job) do
2023-03-17 16:20:25 +05:30
build(:ci_build, ci_stage: stage, pipeline: pipeline, project: project)
2022-01-26 12:08:38 +05:30
end
let(:bridge) do
2023-03-17 16:20:25 +05:30
build(:ci_bridge, ci_stage: stage, pipeline: pipeline, project: project)
2022-01-26 12:08:38 +05:30
end
before do
pipeline.stages = [stage]
stage.statuses = [job, bridge]
end
context 'without tags' do
it 'extracts an empty tag list' do
2022-08-13 15:12:31 +05:30
expect(Gitlab::Ci::Tags::BulkInsert)
2022-01-26 12:08:38 +05:30
.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
2022-08-13 15:12:31 +05:30
expect(Gitlab::Ci::Tags::BulkInsert)
2022-01-26 12:08:38 +05:30
.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
end
2018-03-17 18:26:18 +05:30
end