diff options
Diffstat (limited to 'spec/lib/bulk_imports/clients/http_spec.rb')
-rw-r--r-- | spec/lib/bulk_imports/clients/http_spec.rb | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/spec/lib/bulk_imports/clients/http_spec.rb b/spec/lib/bulk_imports/clients/http_spec.rb index ac42f12a3d4..c36cb80851a 100644 --- a/spec/lib/bulk_imports/clients/http_spec.rb +++ b/spec/lib/bulk_imports/clients/http_spec.rb @@ -5,12 +5,20 @@ require 'spec_helper' RSpec.describe BulkImports::Clients::HTTP do include ImportSpecHelper - let(:uri) { 'http://gitlab.example' } + let(:url) { 'http://gitlab.example' } let(:token) { 'token' } let(:resource) { 'resource' } + let(:version) { "#{BulkImport::MINIMUM_GITLAB_MAJOR_VERSION}.0.0" } let(:response_double) { double(code: 200, success?: true, parsed_response: {}) } + let(:version_response) { double(code: 200, success?: true, parsed_response: { 'version' => version }) } - subject { described_class.new(uri: uri, token: token) } + before do + allow(Gitlab::HTTP).to receive(:get) + .with('http://gitlab.example/api/v4/version', anything) + .and_return(version_response) + end + + subject { described_class.new(url: url, token: token) } shared_examples 'performs network request' do it 'performs network request' do @@ -21,20 +29,20 @@ RSpec.describe BulkImports::Clients::HTTP do context 'error handling' do context 'when error occurred' do - it 'raises ConnectionError' do + it 'raises BulkImports::Error' do allow(Gitlab::HTTP).to receive(method).and_raise(Errno::ECONNREFUSED) - expect { subject.public_send(method, resource) }.to raise_exception(described_class::ConnectionError) + expect { subject.public_send(method, resource) }.to raise_exception(BulkImports::Error) end end context 'when response is not success' do - it 'raises ConnectionError' do + it 'raises BulkImports::Error' do response_double = double(code: 503, success?: false) allow(Gitlab::HTTP).to receive(method).and_return(response_double) - expect { subject.public_send(method, resource) }.to raise_exception(described_class::ConnectionError) + expect { subject.public_send(method, resource) }.to raise_exception(BulkImports::Error) end end end @@ -46,7 +54,7 @@ RSpec.describe BulkImports::Clients::HTTP do include_examples 'performs network request' do let(:expected_args) do [ - 'http://gitlab.example:80/api/v4/resource', + 'http://gitlab.example/api/v4/resource', hash_including( follow_redirects: false, query: { @@ -96,7 +104,7 @@ RSpec.describe BulkImports::Clients::HTTP do private def stub_http_get(path, query, response) - uri = "http://gitlab.example:80/api/v4/#{path}" + uri = "http://gitlab.example/api/v4/#{path}" params = { follow_redirects: false, headers: { @@ -116,7 +124,7 @@ RSpec.describe BulkImports::Clients::HTTP do include_examples 'performs network request' do let(:expected_args) do [ - 'http://gitlab.example:80/api/v4/resource', + 'http://gitlab.example/api/v4/resource', hash_including( body: {}, follow_redirects: false, @@ -136,7 +144,7 @@ RSpec.describe BulkImports::Clients::HTTP do include_examples 'performs network request' do let(:expected_args) do [ - 'http://gitlab.example:80/api/v4/resource', + 'http://gitlab.example/api/v4/resource', hash_including( follow_redirects: false, headers: { @@ -152,7 +160,7 @@ RSpec.describe BulkImports::Clients::HTTP do describe '#stream' do it 'performs network request with stream_body option' do expected_args = [ - 'http://gitlab.example:80/api/v4/resource', + 'http://gitlab.example/api/v4/resource', hash_including( stream_body: true, headers: { @@ -167,4 +175,28 @@ RSpec.describe BulkImports::Clients::HTTP do subject.stream(resource) end end + + context 'when source instance is incompatible' do + let(:version) { '13.0.0' } + + it 'raises an error' do + expect { subject.get(resource) }.to raise_error(::BulkImports::Error, "Unsupported GitLab Version. Minimum Supported Gitlab Version #{BulkImport::MINIMUM_GITLAB_MAJOR_VERSION}.") + end + end + + context 'when url is relative' do + let(:url) { 'http://website.example/gitlab' } + + before do + allow(Gitlab::HTTP).to receive(:get) + .with('http://website.example/gitlab/api/v4/version', anything) + .and_return(version_response) + end + + it 'performs network request to a relative gitlab url' do + expect(Gitlab::HTTP).to receive(:get).with('http://website.example/gitlab/api/v4/resource', anything).and_return(response_double) + + subject.get(resource) + end + end end |