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

sync_dashboards_worker_spec.rb « dashboard « metrics « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f151780ffd744f17fe3cb444f543b8d232bf679e (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Metrics::Dashboard::SyncDashboardsWorker do
  include MetricsDashboardHelpers
  subject(:worker) { described_class.new }

  let(:project) { project_with_dashboard(dashboard_path) }
  let(:dashboard_path) { '.gitlab/dashboards/test.yml' }

  describe ".perform" do
    context 'with valid dashboard hash' do
      it 'imports metrics' do
        expect { worker.perform(project.id) }.to change(PrometheusMetric, :count).by(3)
      end

      it 'is idempotent' do
        2.times do
          worker.perform(project.id)
        end

        expect(PrometheusMetric.count).to eq(3)
      end
    end

    context 'with invalid dashboard hash' do
      before do
        allow_next_instance_of(Gitlab::Metrics::Dashboard::Importer) do |instance|
          allow(instance).to receive(:dashboard_hash).and_return({})
        end
      end

      it 'does not import metrics' do
        expect { worker.perform(project.id) }.not_to change(PrometheusMetric, :count)
      end

      it 'does not raise an error' do
        expect { worker.perform(project.id) }.not_to raise_error
      end
    end
  end
end