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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 18:07:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 18:07:47 +0300
commit6f2065c468b05658125b746169c56764a8ccddb1 (patch)
tree544a488ae2e65e2fcfe4acce4e56623b85bbce5e /spec/services
parente6baeabaa9651d90b03bb64ffce75a2c3cb89aab (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/metrics/dashboard/gitlab_alert_embed_service_spec.rb96
1 files changed, 96 insertions, 0 deletions
diff --git a/spec/services/metrics/dashboard/gitlab_alert_embed_service_spec.rb b/spec/services/metrics/dashboard/gitlab_alert_embed_service_spec.rb
new file mode 100644
index 00000000000..a66150be42c
--- /dev/null
+++ b/spec/services/metrics/dashboard/gitlab_alert_embed_service_spec.rb
@@ -0,0 +1,96 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Metrics::Dashboard::GitlabAlertEmbedService do
+ include MetricsDashboardHelpers
+
+ let_it_be(:alert) { create(:prometheus_alert) }
+ let_it_be(:project) { alert.project }
+ let_it_be(:user) { create(:user) }
+ let(:alert_id) { alert.id }
+
+ before do
+ project.add_maintainer(user)
+ project.clear_memoization(:licensed_feature_available)
+ end
+
+ describe '.valid_params?' do
+ let(:valid_params) do
+ {
+ embedded: true,
+ prometheus_alert_id: alert_id
+ }
+ end
+
+ subject { described_class.valid_params?(params) }
+
+ let(:params) { valid_params }
+
+ it { is_expected.to be_truthy }
+
+ context 'missing embedded' do
+ let(:params) { valid_params.except(:embedded) }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'not embedded' do
+ let(:params) { valid_params.merge(embedded: 'false') }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'missing alert id' do
+ let(:params) { valid_params.except(:prometheus_alert_id) }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'missing alert id' do
+ let(:params) { valid_params.merge(prometheus_alert_id: 'none') }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe '#get_dashboard' do
+ let(:service_params) do
+ [
+ project,
+ user,
+ {
+ embedded: true,
+ prometheus_alert_id: alert_id
+ }
+ ]
+ end
+
+ let(:service_call) { described_class.new(*service_params).get_dashboard }
+
+ context 'when alerting is available' do
+ it_behaves_like 'valid embedded dashboard service response'
+ it_behaves_like 'raises error for users with insufficient permissions'
+
+ it 'uses the metric info corresponding to the alert' do
+ result = service_call
+ metrics = result[:dashboard][:panel_groups][0][:panels][0][:metrics]
+
+ expect(metrics.length).to eq 1
+ expect(metrics.first[:metric_id]).to eq alert.prometheus_metric_id
+ end
+
+ context 'when the metric does not exist' do
+ let(:alert_id) { -4 }
+
+ it_behaves_like 'misconfigured dashboard service response', :not_found
+ end
+
+ it 'does not cache the unprocessed dashboard' do
+ expect(Gitlab::Metrics::Dashboard::Cache).not_to receive(:fetch)
+
+ described_class.new(*service_params).get_dashboard
+ end
+ end
+ end
+end