diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/lib/gitlab/jira_import | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab/jira_import')
-rw-r--r-- | spec/lib/gitlab/jira_import/base_importer_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/jira_import/issues_importer_spec.rb | 35 | ||||
-rw-r--r-- | spec/lib/gitlab/jira_import/labels_importer_spec.rb | 1 |
3 files changed, 22 insertions, 30 deletions
diff --git a/spec/lib/gitlab/jira_import/base_importer_spec.rb b/spec/lib/gitlab/jira_import/base_importer_spec.rb index ecaf3def589..cda491393e8 100644 --- a/spec/lib/gitlab/jira_import/base_importer_spec.rb +++ b/spec/lib/gitlab/jira_import/base_importer_spec.rb @@ -8,27 +8,13 @@ describe Gitlab::JiraImport::BaseImporter do let(:project) { create(:project) } describe 'with any inheriting class' do - context 'when an error is returned from the project validation' do - before do - stub_feature_flags(jira_issue_import: false) - - allow(project).to receive(:validate_jira_import_settings!) - .and_raise(Projects::ImportService::Error, 'Jira import feature is disabled.') - end - - it 'raises exception' do - expect { described_class.new(project) }.to raise_error(Projects::ImportService::Error, 'Jira import feature is disabled.') - end - end - context 'when project validation is ok' do let!(:jira_service) { create(:jira_service, project: project) } before do - stub_feature_flags(jira_issue_import: true) stub_jira_service_test - allow(project).to receive(:validate_jira_import_settings!) + allow(Gitlab::JiraImport).to receive(:validate_project_settings!) end context 'when Jira service exists' do diff --git a/spec/lib/gitlab/jira_import/issues_importer_spec.rb b/spec/lib/gitlab/jira_import/issues_importer_spec.rb index 6cf06c20e19..0d790f49450 100644 --- a/spec/lib/gitlab/jira_import/issues_importer_spec.rb +++ b/spec/lib/gitlab/jira_import/issues_importer_spec.rb @@ -14,7 +14,6 @@ describe Gitlab::JiraImport::IssuesImporter do subject { described_class.new(project) } before do - stub_feature_flags(jira_issue_import: true) stub_jira_service_test end @@ -39,15 +38,22 @@ describe Gitlab::JiraImport::IssuesImporter do end context 'with results returned' do - JiraIssue = Struct.new(:id) - let_it_be(:jira_issues) { [JiraIssue.new(1), JiraIssue.new(2)] } + jira_issue = Struct.new(:id) + let_it_be(:jira_issues) { [jira_issue.new(1), jira_issue.new(2)] } - def mock_issue_serializer(count) + def mock_issue_serializer(count, raise_exception_on_even_mocks: false) serializer = instance_double(Gitlab::JiraImport::IssueSerializer, execute: { key: 'data' }) + next_iid = project.issues.maximum(:iid).to_i count.times do |i| - expect(Gitlab::JiraImport::IssueSerializer).to receive(:new) - .with(project, jira_issues[i], current_user.id, { iid: i + 1 }).and_return(serializer) + if raise_exception_on_even_mocks && i.even? + expect(Gitlab::JiraImport::IssueSerializer).to receive(:new) + .with(project, jira_issues[i], current_user.id, { iid: next_iid + 1 }).and_raise('Some error') + else + next_iid += 1 + expect(Gitlab::JiraImport::IssueSerializer).to receive(:new) + .with(project, jira_issues[i], current_user.id, { iid: next_iid }).and_return(serializer) + end end end @@ -70,21 +76,22 @@ describe Gitlab::JiraImport::IssuesImporter do end end - context 'when there is more than one page of results' do + context 'when importing some issue raises an exception' do before do - stub_const("#{described_class.name}::BATCH_SIZE", 2) + stub_const("#{described_class.name}::BATCH_SIZE", 3) end - it 'schedules 3 import jobs' do + it 'schedules 2 import jobs' do expect(subject).to receive(:fetch_issues).with(0).and_return([jira_issues[0], jira_issues[1]]) - expect(Gitlab::JiraImport::ImportIssueWorker).to receive(:perform_async).twice.times - expect(Gitlab::Cache::Import::Caching).to receive(:set_add).twice.times.and_call_original - expect(Gitlab::Cache::Import::Caching).to receive(:set_includes?).twice.times.and_call_original - mock_issue_serializer(2) + expect(Gitlab::JiraImport::ImportIssueWorker).to receive(:perform_async).once + expect(Gitlab::Cache::Import::Caching).to receive(:set_add).once.and_call_original + expect(Gitlab::Cache::Import::Caching).to receive(:set_includes?).twice.and_call_original + expect(Gitlab::ErrorTracking).to receive(:track_exception).once + mock_issue_serializer(2, raise_exception_on_even_mocks: true) job_waiter = subject.execute - expect(job_waiter.jobs_remaining).to eq(2) + expect(job_waiter.jobs_remaining).to eq(1) expect(Gitlab::JiraImport.get_issues_next_start_at(project.id)).to eq(2) end end diff --git a/spec/lib/gitlab/jira_import/labels_importer_spec.rb b/spec/lib/gitlab/jira_import/labels_importer_spec.rb index 67eb541d376..19661ff4e73 100644 --- a/spec/lib/gitlab/jira_import/labels_importer_spec.rb +++ b/spec/lib/gitlab/jira_import/labels_importer_spec.rb @@ -15,7 +15,6 @@ describe Gitlab::JiraImport::LabelsImporter do subject { importer.execute } before do - stub_feature_flags(jira_issue_import: true) stub_const('Gitlab::JiraImport::LabelsImporter::MAX_LABELS', 2) end |