diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/services/metrics/dashboard/cluster_dashboard_service_spec.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/services/metrics/dashboard/cluster_dashboard_service_spec.rb')
-rw-r--r-- | spec/services/metrics/dashboard/cluster_dashboard_service_spec.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/services/metrics/dashboard/cluster_dashboard_service_spec.rb b/spec/services/metrics/dashboard/cluster_dashboard_service_spec.rb new file mode 100644 index 00000000000..f2e32d5eb35 --- /dev/null +++ b/spec/services/metrics/dashboard/cluster_dashboard_service_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Metrics::Dashboard::ClusterDashboardService, :use_clean_rails_memory_store_caching do + include MetricsDashboardHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:cluster_project) { create(:cluster_project) } + let_it_be(:cluster) { cluster_project.cluster } + let_it_be(:project) { cluster_project.project } + + before do + project.add_maintainer(user) + end + + describe '.valid_params?' do + let(:params) { { cluster: cluster, embedded: 'false' } } + + subject { described_class.valid_params?(params) } + + it { is_expected.to be_truthy } + + context 'with matching dashboard_path' do + let(:params) { { dashboard_path: ::Metrics::Dashboard::ClusterDashboardService::DASHBOARD_PATH } } + + it { is_expected.to be_truthy } + end + + context 'missing cluster without dashboard_path' do + let(:params) { {} } + + it { is_expected.to be_falsey } + end + end + + describe '#get_dashboard' do + let(:service_params) { [project, user, { cluster: cluster, cluster_type: :project }] } + let(:service_call) { subject.get_dashboard } + + subject { described_class.new(*service_params) } + + it_behaves_like 'valid dashboard service response' + it_behaves_like 'caches the unprocessed dashboard for subsequent calls' + it_behaves_like 'refreshes cache when dashboard_version is changed' + + it_behaves_like 'dashboard_version contains SHA256 hash of dashboard file content' do + let(:dashboard_path) { described_class::DASHBOARD_PATH } + let(:dashboard_version) { subject.send(:dashboard_version) } + end + + context 'when called with a non-system dashboard' do + let(:dashboard_path) { 'garbage/dashboard/path' } + + # We want to always return the cluster dashboard. + it_behaves_like 'valid dashboard service response' + end + end +end |