summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/metrics/dashboard/repo_dashboard_finder_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/metrics/dashboard/repo_dashboard_finder_spec.rb')
-rw-r--r--spec/lib/gitlab/metrics/dashboard/repo_dashboard_finder_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics/dashboard/repo_dashboard_finder_spec.rb b/spec/lib/gitlab/metrics/dashboard/repo_dashboard_finder_spec.rb
new file mode 100644
index 00000000000..a2c9906c0e9
--- /dev/null
+++ b/spec/lib/gitlab/metrics/dashboard/repo_dashboard_finder_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Metrics::Dashboard::RepoDashboardFinder do
+ include MetricsDashboardHelpers
+
+ let_it_be(:project) { create(:project) }
+
+ describe '.list_dashboards' do
+ it 'deletes dashboard cache entries' do
+ cache = instance_double(Gitlab::Metrics::Dashboard::Cache)
+ allow(Gitlab::Metrics::Dashboard::Cache).to receive(:for).and_return(cache)
+
+ expect(cache).to receive(:delete_all!)
+
+ described_class.list_dashboards(project)
+ end
+
+ it 'returns empty array when there are no dashboards' do
+ expect(described_class.list_dashboards(project)).to eq([])
+ end
+
+ context 'when there are project dashboards available' do
+ let_it_be(:dashboard_path) { '.gitlab/dashboards/test.yml' }
+ let_it_be(:project) { project_with_dashboard(dashboard_path) }
+
+ it 'returns the dashboard list' do
+ expect(described_class.list_dashboards(project)).to contain_exactly(dashboard_path)
+ end
+ end
+ end
+
+ describe '.read_dashboard' do
+ it 'raises error when dashboard does not exist' do
+ dashboard_path = '.gitlab/dashboards/test.yml'
+
+ expect { described_class.read_dashboard(project, dashboard_path) }.to raise_error(
+ Gitlab::Metrics::Dashboard::Errors::NOT_FOUND_ERROR
+ )
+ end
+
+ context 'when there are project dashboards available' do
+ let_it_be(:dashboard_path) { '.gitlab/dashboards/test.yml' }
+ let_it_be(:project) { project_with_dashboard(dashboard_path) }
+
+ it 'reads dashboard' do
+ expect(described_class.read_dashboard(project, dashboard_path)).to eq(
+ fixture_file('lib/gitlab/metrics/dashboard/sample_dashboard.yml')
+ )
+ end
+ end
+ end
+end