2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Ci::Pipeline::Chain::Build do
|
|
|
|
set(:project) { create(:project, :repository) }
|
|
|
|
set(:user) { create(:user) }
|
|
|
|
let(:pipeline) { Ci::Pipeline.new }
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
let(:variables_attributes) do
|
|
|
|
[{ key: 'first', secret_value: 'world' },
|
|
|
|
{ key: 'second', secret_value: 'second_world' }]
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:command) do
|
|
|
|
Gitlab::Ci::Pipeline::Chain::Command.new(
|
|
|
|
source: :push,
|
|
|
|
origin_ref: 'master',
|
|
|
|
checkout_sha: project.commit.id,
|
|
|
|
after_sha: nil,
|
|
|
|
before_sha: nil,
|
|
|
|
trigger_request: nil,
|
|
|
|
schedule: nil,
|
2019-02-15 15:39:39 +05:30
|
|
|
merge_request: nil,
|
2018-03-17 18:26:18 +05:30
|
|
|
project: project,
|
2018-10-15 14:42:47 +05:30
|
|
|
current_user: user,
|
|
|
|
variables_attributes: variables_attributes)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let(:step) { described_class.new(pipeline, command) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_repository_ci_yaml_file(sha: anything)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'never breaks the chain' do
|
|
|
|
step.perform!
|
|
|
|
|
|
|
|
expect(step.break?).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fills pipeline object with data' do
|
|
|
|
step.perform!
|
|
|
|
|
|
|
|
expect(pipeline.sha).not_to be_empty
|
|
|
|
expect(pipeline.sha).to eq project.commit.id
|
|
|
|
expect(pipeline.ref).to eq 'master'
|
|
|
|
expect(pipeline.tag).to be false
|
|
|
|
expect(pipeline.user).to eq user
|
|
|
|
expect(pipeline.project).to eq project
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(pipeline.variables.map { |var| var.slice(:key, :secret_value) })
|
|
|
|
.to eq variables_attributes.map(&:with_indifferent_access)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets a valid config source' do
|
|
|
|
step.perform!
|
|
|
|
|
|
|
|
expect(pipeline.repository_source?).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a valid pipeline' do
|
|
|
|
step.perform!
|
|
|
|
|
|
|
|
expect(pipeline).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not persist a pipeline' do
|
|
|
|
step.perform!
|
|
|
|
|
|
|
|
expect(pipeline).not_to be_persisted
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline is running for a tag' do
|
|
|
|
let(:command) do
|
|
|
|
Gitlab::Ci::Pipeline::Chain::Command.new(
|
|
|
|
source: :push,
|
|
|
|
origin_ref: 'mytag',
|
|
|
|
checkout_sha: project.commit.id,
|
|
|
|
after_sha: nil,
|
|
|
|
before_sha: nil,
|
|
|
|
trigger_request: nil,
|
|
|
|
schedule: nil,
|
2019-02-15 15:39:39 +05:30
|
|
|
merge_request: nil,
|
2018-03-17 18:26:18 +05:30
|
|
|
project: project,
|
|
|
|
current_user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Repository).to receive(:tag_exists?).with('mytag').and_return(true)
|
|
|
|
|
|
|
|
step.perform!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly indicated that this is a tagged pipeline' do
|
|
|
|
expect(pipeline).to be_tag
|
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
context 'when pipeline is running for a merge request' do
|
|
|
|
let(:command) do
|
|
|
|
Gitlab::Ci::Pipeline::Chain::Command.new(
|
2019-05-30 16:15:17 +05:30
|
|
|
source: :merge_request,
|
2019-02-15 15:39:39 +05:30
|
|
|
origin_ref: 'feature',
|
|
|
|
checkout_sha: project.commit.id,
|
|
|
|
after_sha: nil,
|
|
|
|
before_sha: nil,
|
|
|
|
trigger_request: nil,
|
|
|
|
schedule: nil,
|
|
|
|
merge_request: merge_request,
|
|
|
|
project: project,
|
|
|
|
current_user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:merge_request) { build(:merge_request, target_project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
step.perform!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly indicated that this is a merge request pipeline' do
|
2019-05-30 16:15:17 +05:30
|
|
|
expect(pipeline).to be_merge_request
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(pipeline.merge_request).to eq(merge_request)
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|