2020-10-02 18:08:56 +00:00
|
|
|
# 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
|
2022-01-10 15:14:26 +00:00
|
|
|
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
|
2020-10-02 18:08:56 +00:00
|
|
|
end
|
|
|
|
|
2022-01-10 15:14:26 +00:00
|
|
|
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
|
2020-10-02 18:08:56 +00:00
|
|
|
end
|
|
|
|
|
2022-01-10 15:14:26 +00:00
|
|
|
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
|
2020-10-02 18:08:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|