summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 09:09:17 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 09:09:17 +0000
commiteaea945e0355826c58c3dcf887496ea91064f85c (patch)
tree0f20e03304d35e68375e99a606b9b94483e37ee5 /spec/services
parentcce8cf03d3bebe8b05375e4db0004328f84b28a2 (diff)
downloadgitlab-ce-eaea945e0355826c58c3dcf887496ea91064f85c.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/projects/prometheus/metrics/destroy_service_spec.rb28
-rw-r--r--spec/services/projects/prometheus/metrics/update_service_spec.rb44
2 files changed, 72 insertions, 0 deletions
diff --git a/spec/services/projects/prometheus/metrics/destroy_service_spec.rb b/spec/services/projects/prometheus/metrics/destroy_service_spec.rb
new file mode 100644
index 00000000000..81fce82cf46
--- /dev/null
+++ b/spec/services/projects/prometheus/metrics/destroy_service_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Projects::Prometheus::Metrics::DestroyService do
+ let(:metric) { create(:prometheus_metric) }
+
+ subject { described_class.new(metric) }
+
+ it 'destroys metric' do
+ subject.execute
+
+ expect(PrometheusMetric.find_by(id: metric.id)).to be_nil
+ end
+
+ context 'when metric has a prometheus alert associated' do
+ it 'schedules a prometheus alert update' do
+ create(:prometheus_alert, project: metric.project, prometheus_metric: metric)
+
+ schedule_update_service = spy
+ allow(::Clusters::Applications::ScheduleUpdateService).to receive(:new).and_return(schedule_update_service)
+
+ subject.execute
+
+ expect(schedule_update_service).to have_received(:execute)
+ end
+ end
+end
diff --git a/spec/services/projects/prometheus/metrics/update_service_spec.rb b/spec/services/projects/prometheus/metrics/update_service_spec.rb
new file mode 100644
index 00000000000..a53c6ae37cd
--- /dev/null
+++ b/spec/services/projects/prometheus/metrics/update_service_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Projects::Prometheus::Metrics::UpdateService do
+ let(:metric) { create(:prometheus_metric) }
+
+ it 'updates the prometheus metric' do
+ expect do
+ described_class.new(metric, { title: "bar" }).execute
+ end.to change { metric.reload.title }.to("bar")
+ end
+
+ context 'when metric has a prometheus alert associated' do
+ let(:schedule_update_service) { spy }
+
+ before do
+ create(:prometheus_alert, project: metric.project, prometheus_metric: metric)
+ allow(::Clusters::Applications::ScheduleUpdateService).to receive(:new).and_return(schedule_update_service)
+ end
+
+ context 'when updating title' do
+ it 'schedules a prometheus alert update' do
+ described_class.new(metric, { title: "bar" }).execute
+
+ expect(schedule_update_service).to have_received(:execute)
+ end
+ end
+
+ context 'when updating query' do
+ it 'schedules a prometheus alert update' do
+ described_class.new(metric, { query: "sum(bar)" }).execute
+
+ expect(schedule_update_service).to have_received(:execute)
+ end
+ end
+
+ it 'does not schedule a prometheus alert update without title nor query being changed' do
+ described_class.new(metric, { y_label: "bar" }).execute
+
+ expect(schedule_update_service).not_to have_received(:execute)
+ end
+ end
+end