summaryrefslogtreecommitdiff
path: root/spec/scripts/api/get_package_and_test_job_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/scripts/api/get_package_and_test_job_spec.rb')
-rw-r--r--spec/scripts/api/get_package_and_test_job_spec.rb146
1 files changed, 123 insertions, 23 deletions
diff --git a/spec/scripts/api/get_package_and_test_job_spec.rb b/spec/scripts/api/get_package_and_test_job_spec.rb
index 60bb26cbcaf..aa8f288c255 100644
--- a/spec/scripts/api/get_package_and_test_job_spec.rb
+++ b/spec/scripts/api/get_package_and_test_job_spec.rb
@@ -1,47 +1,147 @@
# frozen_string_literal: true
+# rubocop:disable RSpec/VerifiedDoubles
+
require 'fast_spec_helper'
require_relative '../../../scripts/api/get_package_and_test_job'
RSpec.describe GetPackageAndTestJob, feature_category: :tooling do
describe '#execute' do
- let(:project) { 12345 }
- let(:pipeline_id) { 1 }
-
let(:options) do
{
api_token: 'token',
endpoint: 'https://example.gitlab.com',
- project: project,
- pipeline_id: pipeline_id
+ project: 12345,
+ pipeline_id: 1
}
end
- subject { described_class.new(options).execute }
+ let(:client) { double('Gitlab::Client') }
+ let(:client_response) { double('Gitlab::ClientResponse') }
+ let(:bridge_status) { 'success' }
- it 'requests commit_merge_requests from the gitlab client' do
- client_result = [
- { 'name' => 'foo' },
- { 'name' => 'e2e:package-and-test-ee' },
- { 'name' => 'bar' }
+ let(:bridges_response) do
+ [
+ double(:bridge, id: 1, name: 'foo'),
+ double(:bridge, id: 2, name: 'bar'),
+ double(
+ :bridge,
+ id: 3,
+ name: 'e2e:package-and-test-ee',
+ downstream_pipeline: double(:downstream_pipeline, id: 1),
+ status: bridge_status
+ )
]
- client = double('Gitlab::Client') # rubocop:disable RSpec/VerifiedDoubles
- client_response = double('Gitlab::ClientResponse') # rubocop:disable RSpec/VerifiedDoubles
+ end
- expect(Gitlab).to receive(:client)
- .with(endpoint: options[:endpoint], private_token: options[:api_token])
+ let(:detailed_status_label) { 'passed with warnings' }
+
+ let(:package_and_test_pipeline) do
+ double(
+ :pipeline,
+ id: 1,
+ name: 'e2e:package-and-test-ee',
+ detailed_status: double(
+ :detailed_status,
+ text: 'passed',
+ label: detailed_status_label
+ )
+ )
+ end
+
+ before do
+ allow(Gitlab)
+ .to receive(:client)
.and_return(client)
- expect(client).to receive(:pipeline_bridges).with(
- project, pipeline_id, scope: 'failed', per_page: 100
- ).and_return(client_response)
+ allow(client)
+ .to receive(:pipeline_bridges)
+ .and_return(double(auto_paginate: bridges_response))
+
+ allow(client)
+ .to receive(:pipeline)
+ .and_return(package_and_test_pipeline)
+ end
+
+ subject { described_class.new(options).execute }
+
+ it 'returns a package-and-test pipeline that passed with warnings' do
+ expect(subject).to eq(package_and_test_pipeline)
+ end
+
+ context 'when the bridge can not be found' do
+ let(:bridges_response) { [] }
+
+ it 'returns nothing' do
+ expect(subject).to be_nil
+ end
+ end
+
+ context 'when the downstream pipeline can not be found' do
+ let(:bridges_response) do
+ [
+ double(:bridge, id: 1, name: 'foo'),
+ double(:bridge, id: 2, name: 'bar'),
+ double(
+ :bridge,
+ id: 3,
+ name: 'e2e:package-and-test-ee',
+ downstream_pipeline: nil
+ )
+ ]
+ end
+
+ it 'returns nothing' do
+ expect(subject).to be_nil
+ end
+ end
+
+ context 'when the bridge fails' do
+ let(:bridge_status) { 'failed' }
+
+ it 'returns the downstream_pipeline' do
+ expect(subject).to eq(package_and_test_pipeline)
+ end
+ end
+
+ context 'when the package-and-test can not be found' do
+ let(:package_and_test_pipeline) { nil }
+
+ it 'returns nothing' do
+ expect(subject).to be_nil
+ end
+ end
+
+ context 'when the package-and-test does not include a detailed status' do
+ let(:package_and_test_pipeline) do
+ double(
+ :pipeline,
+ name: 'e2e:package-and-test-ee',
+ detailed_status: nil
+ )
+ end
+
+ it 'returns nothing' do
+ expect(subject).to be_nil
+ end
+ end
- expect(client_response).to receive(:auto_paginate)
- .and_yield(client_result[0])
- .and_yield(client_result[1])
- .and_yield(client_result[2])
+ context 'when the package-and-test succeeds' do
+ let(:detailed_status_label) { 'passed' }
- expect(subject).to eq(client_result[1])
+ it 'returns nothing' do
+ expect(subject).to be_nil
+ end
+ end
+
+ context 'when the package-and-test is canceled' do
+ let(:detailed_status_label) { 'canceled' }
+
+ it 'returns a failed package-and-test pipeline' do
+ expect(subject).to eq(package_and_test_pipeline)
+ end
end
end
end
+
+# rubocop:enable RSpec/VerifiedDoubles