diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /spec/lib/bulk_imports | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/lib/bulk_imports')
-rw-r--r-- | spec/lib/bulk_imports/clients/http_spec.rb | 102 | ||||
-rw-r--r-- | spec/lib/bulk_imports/stage_spec.rb | 34 |
2 files changed, 84 insertions, 52 deletions
diff --git a/spec/lib/bulk_imports/clients/http_spec.rb b/spec/lib/bulk_imports/clients/http_spec.rb index 2d841b7fac2..213fa23675e 100644 --- a/spec/lib/bulk_imports/clients/http_spec.rb +++ b/spec/lib/bulk_imports/clients/http_spec.rb @@ -8,66 +8,23 @@ RSpec.describe BulkImports::Clients::Http do let(:uri) { 'http://gitlab.example' } let(:token) { 'token' } let(:resource) { 'resource' } + let(:response_double) { double(code: 200, success?: true, parsed_response: {}) } subject { described_class.new(uri: uri, token: token) } - describe '#get' do - let(:response_double) { double(code: 200, success?: true, parsed_response: {}) } - - shared_examples 'performs network request' do - it 'performs network request' do - expect(Gitlab::HTTP).to receive(:get).with(*expected_args).and_return(response_double) - - subject.get(resource) - end - end - - describe 'request query' do - include_examples 'performs network request' do - let(:expected_args) do - [ - anything, - hash_including( - query: { - page: described_class::DEFAULT_PAGE, - per_page: described_class::DEFAULT_PER_PAGE - } - ) - ] - end - end - end - - describe 'request headers' do - include_examples 'performs network request' do - let(:expected_args) do - [ - anything, - hash_including( - headers: { - 'Content-Type' => 'application/json', - 'Authorization' => "Bearer #{token}" - } - ) - ] - end - end - end + shared_examples 'performs network request' do + it 'performs network request' do + expect(Gitlab::HTTP).to receive(method).with(*expected_args).and_return(response_double) - describe 'request uri' do - include_examples 'performs network request' do - let(:expected_args) do - ['http://gitlab.example:80/api/v4/resource', anything] - end - end + subject.public_send(method, resource) end context 'error handling' do context 'when error occurred' do it 'raises ConnectionError' do - allow(Gitlab::HTTP).to receive(:get).and_raise(Errno::ECONNREFUSED) + allow(Gitlab::HTTP).to receive(method).and_raise(Errno::ECONNREFUSED) - expect { subject.get(resource) }.to raise_exception(described_class::ConnectionError) + expect { subject.public_send(method, resource) }.to raise_exception(described_class::ConnectionError) end end @@ -75,12 +32,34 @@ RSpec.describe BulkImports::Clients::Http do it 'raises ConnectionError' do response_double = double(code: 503, success?: false) - allow(Gitlab::HTTP).to receive(:get).and_return(response_double) + allow(Gitlab::HTTP).to receive(method).and_return(response_double) - expect { subject.get(resource) }.to raise_exception(described_class::ConnectionError) + expect { subject.public_send(method, resource) }.to raise_exception(described_class::ConnectionError) end end end + end + + describe '#get' do + let(:method) { :get } + + include_examples 'performs network request' do + let(:expected_args) do + [ + 'http://gitlab.example:80/api/v4/resource', + hash_including( + query: { + page: described_class::DEFAULT_PAGE, + per_page: described_class::DEFAULT_PER_PAGE + }, + headers: { + 'Content-Type' => 'application/json', + 'Authorization' => "Bearer #{token}" + } + ) + ] + end + end describe '#each_page' do let(:objects1) { [{ object: 1 }, { object: 2 }] } @@ -129,4 +108,23 @@ RSpec.describe BulkImports::Clients::Http do end end end + + describe '#post' do + let(:method) { :post } + + include_examples 'performs network request' do + let(:expected_args) do + [ + 'http://gitlab.example:80/api/v4/resource', + hash_including( + body: {}, + headers: { + 'Content-Type' => 'application/json', + 'Authorization' => "Bearer #{token}" + } + ) + ] + end + end + end end diff --git a/spec/lib/bulk_imports/stage_spec.rb b/spec/lib/bulk_imports/stage_spec.rb new file mode 100644 index 00000000000..713cd3f22ab --- /dev/null +++ b/spec/lib/bulk_imports/stage_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +RSpec.describe BulkImports::Stage do + let(:pipelines) do + [ + [0, BulkImports::Groups::Pipelines::GroupPipeline], + [1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline], + [1, BulkImports::Groups::Pipelines::MembersPipeline], + [1, BulkImports::Groups::Pipelines::LabelsPipeline], + [1, BulkImports::Groups::Pipelines::MilestonesPipeline], + [1, BulkImports::Groups::Pipelines::BadgesPipeline] + ] + end + + describe '.pipelines' do + it 'list all the pipelines with their stage number, ordered by stage' do + expect(described_class.pipelines & pipelines).to eq(pipelines) + expect(described_class.pipelines.last.last).to eq(BulkImports::Groups::Pipelines::EntityFinisher) + end + end + + describe '.pipeline_exists?' do + it 'returns true when the given pipeline name exists in the pipelines list' do + expect(described_class.pipeline_exists?(BulkImports::Groups::Pipelines::GroupPipeline)).to eq(true) + expect(described_class.pipeline_exists?('BulkImports::Groups::Pipelines::GroupPipeline')).to eq(true) + end + + it 'returns false when the given pipeline name exists in the pipelines list' do + expect(described_class.pipeline_exists?('BulkImports::Groups::Pipelines::InexistentPipeline')).to eq(false) + end + end +end |