2019-03-03 18:56:20 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Ci::PrepareBuildService do
|
|
|
|
describe '#execute' do
|
|
|
|
let(:build) { create(:ci_build, :preparing) }
|
|
|
|
|
|
|
|
subject { described_class.new(build).execute }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(build).to receive(:prerequisites).and_return(prerequisites)
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'build enqueueing' do
|
|
|
|
it 'enqueues the build' do
|
2019-12-24 07:08:01 -05:00
|
|
|
expect(build).to receive(:enqueue_preparing).once
|
2019-03-03 18:56:20 -05:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'build has unmet prerequisites' do
|
|
|
|
let(:prerequisite) { double(complete!: true) }
|
|
|
|
let(:prerequisites) { [prerequisite] }
|
|
|
|
|
|
|
|
it 'completes each prerequisite' do
|
|
|
|
expect(prerequisites).to all(receive(:complete!))
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'build enqueueing'
|
|
|
|
|
|
|
|
context 'prerequisites fail to complete' do
|
|
|
|
before do
|
2019-12-24 07:08:01 -05:00
|
|
|
allow(build).to receive(:enqueue_preparing).and_return(false)
|
2019-03-03 18:56:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'drops the build' do
|
2019-04-14 21:09:30 -04:00
|
|
|
expect(build).to receive(:drop).with(:unmet_prerequisites).once
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'prerequisites raise an error' do
|
|
|
|
before do
|
|
|
|
allow(prerequisite).to receive(:complete!).and_raise Kubeclient::HttpError.new(401, 'unauthorized', nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'drops the build and notifies Sentry' do
|
|
|
|
expect(build).to receive(:drop).with(:unmet_prerequisites).once
|
2019-12-16 07:07:43 -05:00
|
|
|
expect(Gitlab::ErrorTracking).to receive(:track_exception)
|
2019-12-13 07:07:41 -05:00
|
|
|
.with(instance_of(Kubeclient::HttpError), hash_including(build_id: build.id))
|
2019-03-03 18:56:20 -05:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'build has no prerequisites' do
|
|
|
|
let(:prerequisites) { [] }
|
|
|
|
|
|
|
|
include_examples 'build enqueueing'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|