2019-05-02 18:27:35 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe Ci::PlayManualStageService, '#execute' do
|
2019-05-02 18:27:35 +00:00
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
let(:pipeline) { create(:ci_pipeline, user: current_user) }
|
|
|
|
let(:project) { pipeline.project }
|
2020-10-13 09:08:27 +00:00
|
|
|
let(:downstream_project) { create(:project) }
|
2019-05-02 18:27:35 +00:00
|
|
|
let(:service) { described_class.new(project, current_user, pipeline: pipeline) }
|
|
|
|
let(:stage_status) { 'manual' }
|
|
|
|
|
|
|
|
let(:stage) do
|
|
|
|
create(:ci_stage_entity,
|
|
|
|
pipeline: pipeline,
|
|
|
|
project: project,
|
|
|
|
name: 'test')
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_maintainer(current_user)
|
2020-10-13 09:08:27 +00:00
|
|
|
downstream_project.add_maintainer(current_user)
|
2019-05-02 18:27:35 +00:00
|
|
|
create_builds_for_stage(status: stage_status)
|
2020-10-13 09:08:27 +00:00
|
|
|
create_bridge_for_stage(status: stage_status)
|
2019-05-02 18:27:35 +00:00
|
|
|
end
|
|
|
|
|
2020-10-13 09:08:27 +00:00
|
|
|
context 'when pipeline has manual processables' do
|
2019-05-02 18:27:35 +00:00
|
|
|
before do
|
|
|
|
service.execute(stage)
|
|
|
|
end
|
|
|
|
|
2020-10-13 09:08:27 +00:00
|
|
|
it 'starts manual processables from pipeline' do
|
|
|
|
expect(pipeline.processables.manual.count).to eq(0)
|
2019-05-02 18:27:35 +00:00
|
|
|
end
|
|
|
|
|
2020-10-13 09:08:27 +00:00
|
|
|
it 'updates manual processables' do
|
|
|
|
pipeline.processables.each do |processable|
|
|
|
|
expect(processable.user).to eq(current_user)
|
2019-05-02 18:27:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-13 09:08:27 +00:00
|
|
|
context 'when pipeline has no manual processables' do
|
2019-05-02 18:27:35 +00:00
|
|
|
let(:stage_status) { 'failed' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
service.execute(stage)
|
|
|
|
end
|
|
|
|
|
2020-10-13 09:08:27 +00:00
|
|
|
it 'does not update the processables' do
|
|
|
|
expect(pipeline.processables.failed.count).to eq(4)
|
2019-05-02 18:27:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-13 09:08:27 +00:00
|
|
|
context 'when user does not have permission on a specific processable' do
|
2019-05-02 18:27:35 +00:00
|
|
|
before do
|
2020-10-13 09:08:27 +00:00
|
|
|
allow_next_instance_of(Ci::Processable) do |instance|
|
2019-12-16 12:07:43 +00:00
|
|
|
allow(instance).to receive(:play).and_raise(Gitlab::Access::AccessDeniedError)
|
|
|
|
end
|
2019-05-02 18:27:35 +00:00
|
|
|
|
|
|
|
service.execute(stage)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs the error' do
|
|
|
|
expect(Gitlab::AppLogger).to receive(:error)
|
2020-10-13 09:08:27 +00:00
|
|
|
.exactly(stage.processables.manual.count)
|
2019-05-02 18:27:35 +00:00
|
|
|
|
|
|
|
service.execute(stage)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-13 09:08:27 +00:00
|
|
|
private
|
|
|
|
|
2019-05-02 18:27:35 +00:00
|
|
|
def create_builds_for_stage(options)
|
|
|
|
options.merge!({
|
|
|
|
when: 'manual',
|
|
|
|
pipeline: pipeline,
|
|
|
|
stage: stage.name,
|
|
|
|
stage_id: stage.id,
|
|
|
|
user: pipeline.user
|
|
|
|
})
|
|
|
|
|
|
|
|
create_list(:ci_build, 3, options)
|
|
|
|
end
|
2020-10-13 09:08:27 +00:00
|
|
|
|
|
|
|
def create_bridge_for_stage(options)
|
|
|
|
options.merge!({
|
|
|
|
when: 'manual',
|
|
|
|
pipeline: pipeline,
|
|
|
|
stage: stage.name,
|
|
|
|
stage_id: stage.id,
|
|
|
|
user: pipeline.user,
|
|
|
|
downstream: downstream_project
|
|
|
|
})
|
|
|
|
|
|
|
|
create(:ci_bridge, options)
|
|
|
|
end
|
2019-05-02 18:27:35 +00:00
|
|
|
end
|