2019-12-17 07:08:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Metrics::Dashboard::PodDashboardService, :use_clean_rails_memory_store_caching do
|
2019-12-17 07:08:11 -05:00
|
|
|
include MetricsDashboardHelpers
|
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:environment) { create(:environment, project: project) }
|
|
|
|
|
2020-06-26 20:09:17 -04:00
|
|
|
let(:dashboard_path) { described_class::DASHBOARD_PATH }
|
|
|
|
let(:service_params) { [project, user, { environment: environment, dashboard_path: dashboard_path }] }
|
|
|
|
|
2019-12-17 07:08:11 -05:00
|
|
|
before do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
2020-06-26 20:09:17 -04:00
|
|
|
subject { described_class.new(*service_params) }
|
|
|
|
|
|
|
|
describe '#raw_dashboard' do
|
|
|
|
it_behaves_like '#raw_dashboard raises error if dashboard loading fails'
|
|
|
|
end
|
|
|
|
|
2020-01-30 04:08:55 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
describe '#get_dashboard' do
|
2020-04-02 05:08:14 -04:00
|
|
|
let(:service_call) { subject.get_dashboard }
|
|
|
|
|
2019-12-17 07:08:11 -05:00
|
|
|
it_behaves_like 'valid dashboard service response'
|
|
|
|
it_behaves_like 'caches the unprocessed dashboard for subsequent calls'
|
2020-07-16 17:10:05 -04:00
|
|
|
it_behaves_like 'refreshes cache when dashboard_version is changed'
|
2020-04-02 05:08:14 -04:00
|
|
|
it_behaves_like 'updates gitlab_metrics_dashboard_processing_time_ms metric'
|
2020-07-16 17:10:05 -04:00
|
|
|
|
|
|
|
it_behaves_like 'dashboard_version contains SHA256 hash of dashboard file content' do
|
|
|
|
let(:dashboard_version) { subject.send(:dashboard_version) }
|
|
|
|
end
|
2019-12-17 07:08:11 -05:00
|
|
|
end
|
2020-08-04 20:09:52 -04:00
|
|
|
|
|
|
|
describe '.all_dashboard_paths' do
|
|
|
|
it 'returns the dashboard attributes' do
|
|
|
|
all_dashboards = described_class.all_dashboard_paths(project)
|
|
|
|
|
|
|
|
expect(all_dashboards).to eq(
|
|
|
|
[{
|
|
|
|
path: described_class::DASHBOARD_PATH,
|
|
|
|
display_name: described_class::DASHBOARD_NAME,
|
|
|
|
default: false,
|
|
|
|
system_dashboard: false,
|
|
|
|
out_of_the_box_dashboard: true
|
|
|
|
}]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2019-12-17 07:08:11 -05:00
|
|
|
end
|