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

update_service_spec.rb « metrics « prometheus « projects « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a53c6ae37cdeb788a30bbb734597b29c2225a5e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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