Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-13 15:10:03 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-13 15:10:03 +0300
commit75ee59f7a108cf0c57e1e66e3ef5e439bae24fcd (patch)
treeb2f1ec89e16c6b27041f608c9fb12b7586e5ce94 /spec
parente79918ce90dc31527be1ef0140a99cfe450d931e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/static_site_editor_controller_spec.rb15
-rw-r--r--spec/frontend/logs/components/environment_logs_spec.js10
-rw-r--r--spec/frontend/vue_mr_widget/components/mr_widget_terraform_plan_spec.js89
-rw-r--r--spec/lib/gitlab/metrics/dashboard/processor_spec.rb52
-rw-r--r--spec/lib/gitlab/static_site_editor/config_spec.rb30
-rw-r--r--spec/workers/concerns/project_import_options_spec.rb11
6 files changed, 202 insertions, 5 deletions
diff --git a/spec/controllers/projects/static_site_editor_controller_spec.rb b/spec/controllers/projects/static_site_editor_controller_spec.rb
index 7f1b67fc734..d1224bb75c0 100644
--- a/spec/controllers/projects/static_site_editor_controller_spec.rb
+++ b/spec/controllers/projects/static_site_editor_controller_spec.rb
@@ -10,7 +10,8 @@ describe Projects::StaticSiteEditorController do
{
namespace_id: project.namespace,
project_id: project,
- id: 'master/README.md'
+ id: 'master/README.md',
+ return_url: 'http://example.com'
}
end
@@ -38,6 +39,18 @@ describe Projects::StaticSiteEditorController do
it 'renders the edit page' do
expect(response).to render_template(:show)
end
+
+ it 'assigns a config variable' do
+ expect(assigns(:config)).to be_a(Gitlab::StaticSiteEditor::Config)
+ end
+
+ context 'when combination of ref and file path is incorrect' do
+ let(:default_params) { super().merge(id: 'unknown') }
+
+ it 'responds with 404 page' do
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
end
end
end
diff --git a/spec/frontend/logs/components/environment_logs_spec.js b/spec/frontend/logs/components/environment_logs_spec.js
index befcd462828..d097610cb0a 100644
--- a/spec/frontend/logs/components/environment_logs_spec.js
+++ b/spec/frontend/logs/components/environment_logs_spec.js
@@ -43,7 +43,7 @@ describe('EnvironmentLogs', () => {
const findSimpleFilters = () => wrapper.find({ ref: 'log-simple-filters' });
const findAdvancedFilters = () => wrapper.find({ ref: 'log-advanced-filters' });
- const findInfoAlert = () => wrapper.find('.js-elasticsearch-alert');
+ const findElasticsearchNotice = () => wrapper.find({ ref: 'elasticsearchNotice' });
const findLogControlButtons = () => wrapper.find({ name: 'log-control-buttons-stub' });
const findInfiniteScroll = () => wrapper.find({ ref: 'infiniteScroll' });
@@ -160,6 +160,10 @@ describe('EnvironmentLogs', () => {
initWrapper();
});
+ it('does not display an alert to upgrade to ES', () => {
+ expect(findElasticsearchNotice().exists()).toBe(false);
+ });
+
it('displays a disabled environments dropdown', () => {
expect(findEnvironmentsDropdown().attributes('disabled')).toBe('true');
expect(findEnvironmentsDropdown().findAll(GlDropdownItem).length).toBe(0);
@@ -204,7 +208,7 @@ describe('EnvironmentLogs', () => {
});
it('displays an alert to upgrade to ES', () => {
- expect(findInfoAlert().exists()).toBe(true);
+ expect(findElasticsearchNotice().exists()).toBe(true);
});
it('displays simple filters for kubernetes logs API', () => {
@@ -235,7 +239,7 @@ describe('EnvironmentLogs', () => {
});
it('does not display an alert to upgrade to ES', () => {
- expect(findInfoAlert().exists()).toBe(false);
+ expect(findElasticsearchNotice().exists()).toBe(false);
});
it('populates environments dropdown', () => {
diff --git a/spec/frontend/vue_mr_widget/components/mr_widget_terraform_plan_spec.js b/spec/frontend/vue_mr_widget/components/mr_widget_terraform_plan_spec.js
new file mode 100644
index 00000000000..1951b56587a
--- /dev/null
+++ b/spec/frontend/vue_mr_widget/components/mr_widget_terraform_plan_spec.js
@@ -0,0 +1,89 @@
+import { GlLoadingIcon, GlSprintf } from '@gitlab/ui';
+import { shallowMount } from '@vue/test-utils';
+import axios from '~/lib/utils/axios_utils';
+import MockAdapter from 'axios-mock-adapter';
+import MrWidgetTerraformPlan from '~/vue_merge_request_widget/components/mr_widget_terraform_plan.vue';
+
+const plan = {
+ create: 10,
+ update: 20,
+ delete: 30,
+ job_path: '/path/to/ci/logs',
+};
+
+describe('MrWidgetTerraformPlan', () => {
+ let mock;
+ let wrapper;
+
+ const propsData = { endpoint: '/path/to/terraform/report.json' };
+
+ const mockPollingApi = (response, body, header) => {
+ mock.onGet(propsData.endpoint).reply(response, body, header);
+ };
+
+ const mountWrapper = () => {
+ wrapper = shallowMount(MrWidgetTerraformPlan, { propsData });
+ return axios.waitForAll();
+ };
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ });
+
+ afterEach(() => {
+ wrapper.destroy();
+ mock.restore();
+ });
+
+ describe('loading poll', () => {
+ beforeEach(() => {
+ mockPollingApi(200, { 'tfplan.json': plan }, {});
+
+ return mountWrapper().then(() => {
+ wrapper.setData({ loading: true });
+ return wrapper.vm.$nextTick();
+ });
+ });
+
+ it('Diplays loading icon when loading is true', () => {
+ expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
+
+ expect(wrapper.find(GlSprintf).exists()).toBe(false);
+
+ expect(wrapper.text()).not.toContain(
+ 'A terraform report was generated in your pipelines. Changes are unknown',
+ );
+ });
+ });
+
+ describe('successful poll', () => {
+ beforeEach(() => {
+ mockPollingApi(200, { 'tfplan.json': plan }, {});
+ return mountWrapper();
+ });
+
+ it('content change text', () => {
+ expect(wrapper.find(GlSprintf).exists()).toBe(true);
+ });
+
+ it('renders button when url is found', () => {
+ expect(wrapper.find('a').text()).toContain('View full log');
+ });
+ });
+
+ describe('polling fails', () => {
+ beforeEach(() => {
+ mockPollingApi(500, null, {});
+ return mountWrapper();
+ });
+
+ it('does not display changes text when api fails', () => {
+ expect(wrapper.text()).toContain(
+ 'A terraform report was generated in your pipelines. Changes are unknown',
+ );
+
+ expect(wrapper.find('.js-terraform-report-link').exists()).toBe(false);
+ expect(wrapper.text()).not.toContain('View full log');
+ });
+ });
+});
diff --git a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb
index d957b1c992f..3cb02a8bcb3 100644
--- a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb
+++ b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb
@@ -14,9 +14,11 @@ describe Gitlab::Metrics::Dashboard::Processor do
Gitlab::Metrics::Dashboard::Stages::CustomMetricsInserter,
Gitlab::Metrics::Dashboard::Stages::CustomMetricsDetailsInserter,
Gitlab::Metrics::Dashboard::Stages::EndpointInserter,
- Gitlab::Metrics::Dashboard::Stages::Sorter
+ Gitlab::Metrics::Dashboard::Stages::Sorter,
+ Gitlab::Metrics::Dashboard::Stages::AlertsInserter
]
end
+
let(:process_params) { [project, dashboard_yml, sequence, { environment: environment }] }
let(:dashboard) { described_class.new(*process_params).process }
@@ -113,6 +115,54 @@ describe Gitlab::Metrics::Dashboard::Processor do
end
end
+ context 'when the dashboard references persisted metrics with alerts' do
+ let!(:alert) do
+ create(
+ :prometheus_alert,
+ environment: environment,
+ project: project,
+ prometheus_metric: persisted_metric
+ )
+ end
+
+ shared_examples_for 'has saved alerts' do
+ it 'includes an alert path' do
+ target_metric = all_metrics.find { |metric| metric[:metric_id] == persisted_metric.id }
+
+ expect(target_metric).to be_a Hash
+ expect(target_metric).to include(:alert_path)
+ expect(target_metric[:alert_path]).to include(
+ project.path,
+ persisted_metric.id.to_s,
+ environment.id.to_s
+ )
+ end
+ end
+
+ context 'that are shared across projects' do
+ let!(:persisted_metric) { create(:prometheus_metric, :common, identifier: 'metric_a1') }
+
+ it_behaves_like 'has saved alerts'
+ end
+
+ context 'when the project has associated metrics' do
+ let!(:persisted_metric) { create(:prometheus_metric, project: project, group: :business) }
+
+ it_behaves_like 'has saved alerts'
+ end
+ end
+
+ context 'when there are no alerts' do
+ let!(:persisted_metric) { create(:prometheus_metric, :common, identifier: 'metric_a1') }
+
+ it 'does not insert an alert_path' do
+ target_metric = all_metrics.find { |metric| metric[:metric_id] == persisted_metric.id }
+
+ expect(target_metric).to be_a Hash
+ expect(target_metric).not_to include(:alert_path)
+ end
+ end
+
shared_examples_for 'errors with message' do |expected_message|
it 'raises a DashboardLayoutError' do
error_class = Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError
diff --git a/spec/lib/gitlab/static_site_editor/config_spec.rb b/spec/lib/gitlab/static_site_editor/config_spec.rb
new file mode 100644
index 00000000000..dea79fb0e92
--- /dev/null
+++ b/spec/lib/gitlab/static_site_editor/config_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::StaticSiteEditor::Config do
+ subject(:config) { described_class.new(repository, ref, file_path, return_url) }
+
+ let(:project) { create(:project, :public, :repository, name: 'project', namespace: namespace) }
+ let(:namespace) { create(:namespace, name: 'namespace') }
+ let(:repository) { project.repository }
+ let(:ref) { 'master' }
+ let(:file_path) { 'README.md' }
+ let(:return_url) { 'http://example.com' }
+
+ describe '#payload' do
+ subject { config.payload }
+
+ it 'returns data for the frontend component' do
+ is_expected.to eq(
+ branch: 'master',
+ commit: repository.commit.id,
+ namespace: 'namespace',
+ path: 'README.md',
+ project: 'project',
+ project_id: project.id,
+ return_url: 'http://example.com'
+ )
+ end
+ end
+end
diff --git a/spec/workers/concerns/project_import_options_spec.rb b/spec/workers/concerns/project_import_options_spec.rb
index c5fbcfb5fb0..3ccfb21b653 100644
--- a/spec/workers/concerns/project_import_options_spec.rb
+++ b/spec/workers/concerns/project_import_options_spec.rb
@@ -39,6 +39,17 @@ describe ProjectImportOptions do
expect(project.import_state.reload.last_error).to include("import")
end
+ context 'when project is jira import' do
+ let(:project) { create(:project, import_type: 'jira') }
+ let!(:jira_import) { create(:jira_import_state, project: project) }
+
+ it 'logs the appropriate error message for forked projects' do
+ worker_class.sidekiq_retries_exhausted_block.call(job)
+
+ expect(project.latest_jira_import.reload.status).to eq('failed')
+ end
+ end
+
context 'when project does not have import_state' do
let(:project) { create(:project) }