diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 18:08:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 18:08:52 +0300 |
commit | 0ab47b994caa80c5587f33dc818626b66cfdafe2 (patch) | |
tree | 5ef3976d2f84e3368903a67ba2dbd87a74b9a43c /spec/services/metrics | |
parent | 1308dc5eb484ab0f8064989fc551ebdb4b1a7976 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/metrics')
-rw-r--r-- | spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb b/spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb new file mode 100644 index 00000000000..9ee5b06b410 --- /dev/null +++ b/spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Metrics::Dashboard::SelfMonitoringDashboardService, :use_clean_rails_memory_store_caching do + include MetricsDashboardHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:environment) { create(:environment, project: project) } + + before do + project.add_maintainer(user) + stub_application_setting(self_monitoring_project_id: project.id) + end + + describe '#get_dashboard' do + let(:service_params) { [project, user, { environment: environment }] } + let(:service_call) { described_class.new(*service_params).get_dashboard } + + it_behaves_like 'valid dashboard service response' + it_behaves_like 'raises error for users with insufficient permissions' + it_behaves_like 'caches the unprocessed dashboard for subsequent calls' + end + + 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: true, + system_dashboard: false + }] + ) + end + end + + describe '.valid_params?' do + subject { described_class.valid_params?(params) } + + context 'with environment' do + let(:params) { { environment: environment } } + + it { is_expected.to be_truthy } + end + + context 'with dashboard_path' do + let(:params) { { dashboard_path: self_monitoring_dashboard_path } } + + it { is_expected.to be_truthy } + end + + context 'with a different dashboard selected' do + let(:dashboard_path) { '.gitlab/dashboards/test.yml' } + let(:params) { { dashboard_path: dashboard_path, environment: environment } } + + it { is_expected.to be_falsey } + end + + context 'missing environment and dashboard_path' do + let(:params) { {} } + + it { is_expected.to be_falsey } + end + end +end |