diff options
Diffstat (limited to 'spec/lib/bulk_imports/clients/http_spec.rb')
-rw-r--r-- | spec/lib/bulk_imports/clients/http_spec.rb | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/spec/lib/bulk_imports/clients/http_spec.rb b/spec/lib/bulk_imports/clients/http_spec.rb index 780f61f8c61..aff049408e2 100644 --- a/spec/lib/bulk_imports/clients/http_spec.rb +++ b/spec/lib/bulk_imports/clients/http_spec.rb @@ -10,6 +10,7 @@ RSpec.describe BulkImports::Clients::HTTP, feature_category: :importers do let(:resource) { 'resource' } let(:version) { "#{BulkImport::MIN_MAJOR_VERSION}.0.0" } let(:enterprise) { false } + let(:sidekiq_request_timeout) { described_class::SIDEKIQ_REQUEST_TIMEOUT } let(:response_double) { double(code: 200, success?: true, parsed_response: {}) } let(:metadata_response) do double( @@ -123,6 +124,36 @@ RSpec.describe BulkImports::Clients::HTTP, feature_category: :importers do allow(Gitlab::HTTP).to receive(:get).with(uri, params).and_return(response) end end + + context 'when the request is asynchronous' do + let(:expected_args) do + [ + 'http://gitlab.example/api/v4/resource', + hash_including( + query: { + page: described_class::DEFAULT_PAGE, + per_page: described_class::DEFAULT_PER_PAGE, + private_token: token + }, + headers: { + 'Content-Type' => 'application/json' + }, + follow_redirects: true, + resend_on_redirect: false, + limit: 2, + timeout: sidekiq_request_timeout + ) + ] + end + + it 'sets a timeout that is double the default read timeout' do + allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) + + expect(Gitlab::HTTP).to receive(method).with(*expected_args).and_return(response_double) + + subject.public_send(method, resource) + end + end end describe '#post' do @@ -230,7 +261,7 @@ RSpec.describe BulkImports::Clients::HTTP, feature_category: :importers do .to_return(status: 401, body: "", headers: { 'Content-Type' => 'application/json' }) expect { subject.instance_version }.to raise_exception(BulkImports::Error, - "Import aborted as the provided personal access token does not have the required 'api' scope or " \ + "Personal access token does not have the required 'api' scope or " \ "is no longer valid.") end end @@ -242,7 +273,7 @@ RSpec.describe BulkImports::Clients::HTTP, feature_category: :importers do .to_return(status: 403, body: "", headers: { 'Content-Type' => 'application/json' }) expect { subject.instance_version }.to raise_exception(BulkImports::Error, - "Import aborted as the provided personal access token does not have the required 'api' scope or " \ + "Personal access token does not have the required 'api' scope or " \ "is no longer valid.") end end @@ -253,7 +284,7 @@ RSpec.describe BulkImports::Clients::HTTP, feature_category: :importers do stub_request(:get, 'http://gitlab.example/api/v4/metadata?private_token=token') .to_return(status: 404, body: "", headers: { 'Content-Type' => 'application/json' }) - expect { subject.instance_version }.to raise_exception(BulkImports::Error, 'Import aborted as it was not possible to connect to the provided GitLab instance URL.') + expect { subject.instance_version }.to raise_exception(BulkImports::Error, 'Invalid source URL. Enter only the base URL of the source GitLab instance.') end end |