debian-mirror-gitlab/spec/services/ci/prepare_build_service_spec.rb

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

69 lines
1.8 KiB
Ruby
Raw Permalink Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Ci::PrepareBuildService, feature_category: :continuous_integration do
2019-07-07 11:18:12 +05:30
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
2020-03-13 15:44:24 +05:30
expect(build).to receive(:enqueue_preparing).once
2019-07-07 11:18:12 +05:30
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
2020-03-13 15:44:24 +05:30
allow(build).to receive(:enqueue_preparing).and_return(false)
2019-07-07 11:18:12 +05:30
end
it 'drops the build' do
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
2020-01-01 13:55:28 +05:30
expect(Gitlab::ErrorTracking).to receive(:track_exception)
.with(instance_of(Kubeclient::HttpError), hash_including(build_id: build.id))
2019-07-07 11:18:12 +05:30
subject
end
end
end
context 'build has no prerequisites' do
let(:prerequisites) { [] }
include_examples 'build enqueueing'
end
end
end