diff options
Diffstat (limited to 'spec/services/import')
-rw-r--r-- | spec/services/import/github_service_spec.rb | 69 |
1 files changed, 44 insertions, 25 deletions
diff --git a/spec/services/import/github_service_spec.rb b/spec/services/import/github_service_spec.rb index 266ff309662..408d7767254 100644 --- a/spec/services/import/github_service_spec.rb +++ b/spec/services/import/github_service_spec.rb @@ -6,7 +6,6 @@ RSpec.describe Import::GithubService do let_it_be(:user) { create(:user) } let_it_be(:token) { 'complex-token' } let_it_be(:access_params) { { github_access_token: 'github-complex-token' } } - let_it_be(:client) { Gitlab::LegacyGithubImport::Client.new(token) } let_it_be(:params) { { repo_id: 123, new_name: 'new_repo', target_namespace: 'root' } } let(:subject) { described_class.new(client, user, params) } @@ -15,41 +14,61 @@ RSpec.describe Import::GithubService do allow(subject).to receive(:authorized?).and_return(true) end - context 'do not raise an exception on input error' do - let(:exception) { Octokit::ClientError.new(status: 404, body: 'Not Found') } + shared_examples 'handles errors' do |klass| + let(:client) { klass.new(token) } - before do - expect(client).to receive(:repo).and_raise(exception) - end + context 'do not raise an exception on input error' do + let(:exception) { Octokit::ClientError.new(status: 404, body: 'Not Found') } + + before do + expect(client).to receive(:repository).and_raise(exception) + end - it 'logs the original error' do - expect(Gitlab::Import::Logger).to receive(:error).with({ - message: 'Import failed due to a GitHub error', - status: 404, - error: 'Not Found' - }).and_call_original + it 'logs the original error' do + expect(Gitlab::Import::Logger).to receive(:error).with({ + message: 'Import failed due to a GitHub error', + status: 404, + error: 'Not Found' + }).and_call_original - subject.execute(access_params, :github) + subject.execute(access_params, :github) + end + + it 'returns an error' do + result = subject.execute(access_params, :github) + + expect(result).to include( + message: 'Import failed due to a GitHub error: Not Found', + status: :error, + http_status: :unprocessable_entity + ) + end end - it 'returns an error' do - result = subject.execute(access_params, :github) + it 'raises an exception for unknown error causes' do + exception = StandardError.new('Not Implemented') + + expect(client).to receive(:repository).and_raise(exception) - expect(result).to include( - message: 'Import failed due to a GitHub error: Not Found', - status: :error, - http_status: :unprocessable_entity - ) + expect(Gitlab::Import::Logger).not_to receive(:error) + + expect { subject.execute(access_params, :github) }.to raise_error(exception) end end - it 'raises an exception for unknown error causes' do - exception = StandardError.new('Not Implemented') + context 'when remove_legacy_github_client feature flag is enabled' do + before do + stub_feature_flags(remove_legacy_github_client: true) + end - expect(client).to receive(:repo).and_raise(exception) + include_examples 'handles errors', Gitlab::GithubImport::Client + end - expect(Gitlab::Import::Logger).not_to receive(:error) + context 'when remove_legacy_github_client feature flag is enabled' do + before do + stub_feature_flags(remove_legacy_github_client: false) + end - expect { subject.execute(access_params, :github) }.to raise_error(exception) + include_examples 'handles errors', Gitlab::LegacyGithubImport::Client end end |