diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-13 12:10:03 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-13 12:10:03 +0000 |
commit | 75ee59f7a108cf0c57e1e66e3ef5e439bae24fcd (patch) | |
tree | b2f1ec89e16c6b27041f608c9fb12b7586e5ce94 /spec/lib | |
parent | e79918ce90dc31527be1ef0140a99cfe450d931e (diff) | |
download | gitlab-ce-75ee59f7a108cf0c57e1e66e3ef5e439bae24fcd.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/metrics/dashboard/processor_spec.rb | 52 | ||||
-rw-r--r-- | spec/lib/gitlab/static_site_editor/config_spec.rb | 30 |
2 files changed, 81 insertions, 1 deletions
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 |