diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 12:07:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 12:07:45 +0300 |
commit | b11f7057d067885619ee3e513751f180b2e8ad85 (patch) | |
tree | dfb3077ea8716ed217f5ce4324be4e25a450c599 /spec/lib/gitlab | |
parent | e50050a8756a20b6aa118edbad3369674e4c63ba (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/jira_import/labels_importer_spec.rb | 48 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_spec.rb | 24 |
2 files changed, 72 insertions, 0 deletions
diff --git a/spec/lib/gitlab/jira_import/labels_importer_spec.rb b/spec/lib/gitlab/jira_import/labels_importer_spec.rb new file mode 100644 index 00000000000..eaa13d9ed32 --- /dev/null +++ b/spec/lib/gitlab/jira_import/labels_importer_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::JiraImport::LabelsImporter do + let(:user) { create(:user) } + let(:jira_import_data) do + data = JiraImportData.new + data << JiraImportData::JiraProjectDetails.new('XX', Time.now.strftime('%Y-%m-%d %H:%M:%S'), { user_id: user.id, name: user.name }) + data + end + let(:project) { create(:project, import_data: jira_import_data) } + let!(:jira_service) { create(:jira_service, project: project) } + + subject { described_class.new(project).execute } + + before do + stub_feature_flags(jira_issue_import: true) + end + + describe '#execute', :clean_gitlab_redis_cache do + context 'when label creation failes' do + before do + allow_next_instance_of(Labels::CreateService) do |instance| + allow(instance).to receive(:execute).and_return(nil) + end + end + + it 'raises error' do + expect { subject }.to raise_error(Projects::ImportService::Error, 'Failed to create import label for jira import.') + end + end + + context 'when label is created successfully' do + it 'creates import label' do + expect { subject }.to change { Label.count }.by(1) + end + + it 'caches import label' do + expect(Gitlab::Cache::Import::Caching.read(Gitlab::JiraImport.import_label_cache_key(project.id))).to be nil + + subject + + expect(Gitlab::JiraImport.get_import_label_id(project.id).to_i).to be > 0 + end + end + end +end diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index c148f5e63a5..eca69d755cc 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -147,6 +147,8 @@ describe Gitlab::UsageData, :aggregate_failures do subject { described_class.components_usage_data } it 'gathers components usage data' do + expect(Gitlab::UsageData).to receive(:app_server_type).and_return('server_type') + expect(subject[:app_server][:type]).to eq('server_type') expect(subject[:gitlab_pages][:enabled]).to eq(Gitlab.config.pages.enabled) expect(subject[:gitlab_pages][:version]).to eq(Gitlab::Pages::VERSION) expect(subject[:git][:version]).to eq(Gitlab::Git.version) @@ -159,6 +161,28 @@ describe Gitlab::UsageData, :aggregate_failures do end end + describe '#app_server_type' do + subject { described_class.app_server_type } + + it 'successfully identifies runtime and returns the identifier' do + expect(Gitlab::Runtime).to receive(:identify).and_return(:runtime_identifier) + + is_expected.to eq('runtime_identifier') + end + + context 'when runtime is not identified' do + let(:exception) { Gitlab::Runtime::IdentificationError.new('exception message from runtime identify') } + + it 'logs the exception and returns unknown app server type' do + expect(Gitlab::Runtime).to receive(:identify).and_raise(exception) + + expect(Gitlab::AppLogger).to receive(:error).with(exception.message) + expect(Gitlab::ErrorTracking).to receive(:track_exception).with(exception) + expect(subject).to eq('unknown_app_server_type') + end + end + end + describe '#cycle_analytics_usage_data' do subject { described_class.cycle_analytics_usage_data } |