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

97 lines
2.2 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::Skip do
2020-04-08 14:13:33 +05:30
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:pipeline, reload: true) { create(:ci_pipeline, project: project) }
2018-03-17 18:26:18 +05:30
let(:command) do
Gitlab::Ci::Pipeline::Chain::Command.new(
project: project,
current_user: user,
ignore_skip_ci: false,
save_incompleted: true)
end
let(:step) { described_class.new(pipeline, command) }
context 'when pipeline has been skipped by a user' do
before do
allow(pipeline).to receive(:git_commit_message)
.and_return('commit message [ci skip]')
end
2019-07-07 11:18:12 +05:30
it 'breaks the chain' do
2021-06-08 01:23:25 +05:30
step.perform!
2018-03-17 18:26:18 +05:30
expect(step.break?).to be true
end
it 'skips the pipeline' do
2021-06-08 01:23:25 +05:30
step.perform!
2018-03-17 18:26:18 +05:30
expect(pipeline.reload).to be_skipped
end
2021-06-08 01:23:25 +05:30
it 'calls ensure_project_iid explicitly' do
expect(pipeline).to receive(:ensure_project_iid!)
step.perform!
end
2018-03-17 18:26:18 +05:30
end
context 'when pipeline has not been skipped' do
before do
step.perform!
end
2019-07-07 11:18:12 +05:30
it 'does not break the chain' do
2018-03-17 18:26:18 +05:30
expect(step.break?).to be false
end
2019-07-07 11:18:12 +05:30
it 'does not skip a pipeline chain' do
2018-03-17 18:26:18 +05:30
expect(pipeline.reload).not_to be_skipped
end
end
context 'when [ci skip] should be ignored' do
let(:command) do
double('command', project: project,
current_user: user,
ignore_skip_ci: true)
end
it 'does not break the chain' do
step.perform!
expect(step.break?).to be false
end
end
context 'when pipeline should be skipped but not persisted' do
let(:command) do
double('command', project: project,
current_user: user,
ignore_skip_ci: false,
save_incompleted: false)
end
before do
allow(pipeline).to receive(:git_commit_message)
.and_return('commit message [ci skip]')
step.perform!
end
it 'breaks the chain' do
expect(step.break?).to be true
end
it 'does not skip pipeline' do
expect(pipeline.reload).not_to be_skipped
end
end
end