debian-mirror-gitlab/spec/services/metrics/dashboard/system_dashboard_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.5 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Metrics::Dashboard::SystemDashboardService, :use_clean_rails_memory_store_caching,
feature_category: :metrics do
2019-07-31 22:56:46 +05:30
include MetricsDashboardHelpers
2020-03-13 15:44:24 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:environment) { create(:environment, project: project) }
2019-07-31 22:56:46 +05:30
2020-07-28 23:09:34 +05:30
let(:dashboard_path) { described_class::DASHBOARD_PATH }
let(:service_params) { [project, user, { environment: environment, dashboard_path: dashboard_path }] }
subject { described_class.new(*service_params) }
2019-09-30 21:07:59 +05:30
before do
2022-06-21 17:19:12 +05:30
project.add_maintainer(user) if user
2019-09-30 21:07:59 +05:30
end
2020-07-28 23:09:34 +05:30
describe '#raw_dashboard' do
it_behaves_like '#raw_dashboard raises error if dashboard loading fails'
end
2020-03-13 15:44:24 +05:30
describe '#get_dashboard' do
2020-04-22 19:07:51 +05:30
let(:service_call) { subject.get_dashboard }
2019-07-31 22:56:46 +05:30
it_behaves_like 'valid dashboard service response'
2019-09-30 21:07:59 +05:30
it_behaves_like 'raises error for users with insufficient permissions'
2020-01-01 13:55:28 +05:30
it_behaves_like 'caches the unprocessed dashboard for subsequent calls'
2020-07-28 23:09:34 +05:30
it_behaves_like 'refreshes cache when dashboard_version is changed'
2020-04-22 19:07:51 +05:30
it_behaves_like 'updates gitlab_metrics_dashboard_processing_time_ms metric'
2019-07-31 22:56:46 +05:30
2020-07-28 23:09:34 +05:30
it_behaves_like 'dashboard_version contains SHA256 hash of dashboard file content' do
let(:dashboard_version) { subject.send(:dashboard_version) }
end
2019-07-31 22:56:46 +05:30
context 'when called with a non-system dashboard' do
let(:dashboard_path) { 'garbage/dashboard/path' }
2020-01-01 13:55:28 +05:30
# We want to always return the system dashboard.
2019-07-31 22:56:46 +05:30
it_behaves_like 'valid dashboard service response'
end
end
2019-09-04 21:01:54 +05:30
2020-03-13 15:44:24 +05:30
describe '.all_dashboard_paths' do
2019-09-04 21:01:54 +05:30
it 'returns the dashboard attributes' do
all_dashboards = described_class.all_dashboard_paths(project)
expect(all_dashboards).to eq(
[{
2020-01-01 13:55:28 +05:30
path: described_class::DASHBOARD_PATH,
display_name: described_class::DASHBOARD_NAME,
2019-12-26 22:10:19 +05:30
default: true,
2020-07-28 23:09:34 +05:30
system_dashboard: true,
out_of_the_box_dashboard: true
2019-09-04 21:01:54 +05:30
}]
)
end
end
2020-03-13 15:44:24 +05:30
describe '.valid_params?' do
let(:params) { { dashboard_path: described_class::DASHBOARD_PATH } }
subject { described_class.valid_params?(params) }
it { is_expected.to be_truthy }
context 'missing dashboard_path' do
let(:params) { {} }
it { is_expected.to be_falsey }
end
context 'non-matching dashboard_path' do
let(:params) { { dashboard_path: 'path/to/bunk.yml' } }
it { is_expected.to be_falsey }
end
end
2019-07-31 22:56:46 +05:30
end