2019-04-16 12:08:04 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-16 03:01:43 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-04-16 05:09:10 -04:00
|
|
|
describe Gitlab::MetricsDashboard::Service, :use_clean_rails_memory_store_caching do
|
2019-04-16 03:15:57 -04:00
|
|
|
let(:project) { build(:project) }
|
2019-04-17 07:37:42 -04:00
|
|
|
let(:environment) { build(:environment) }
|
2019-04-16 03:01:43 -04:00
|
|
|
|
|
|
|
describe 'get_dashboard' do
|
2019-04-17 05:51:42 -04:00
|
|
|
let(:dashboard_schema) { JSON.parse(fixture_file('lib/gitlab/metrics_dashboard/schemas/dashboard.json')) }
|
|
|
|
|
2019-04-16 03:01:43 -04:00
|
|
|
it 'returns a json representation of the environment dashboard' do
|
2019-04-17 07:37:42 -04:00
|
|
|
result = described_class.new(project, environment).get_dashboard
|
2019-04-16 03:01:43 -04:00
|
|
|
|
2019-04-17 05:46:11 -04:00
|
|
|
expect(result.keys).to contain_exactly(:dashboard, :status)
|
|
|
|
expect(result[:status]).to eq(:success)
|
|
|
|
|
2019-04-17 05:51:42 -04:00
|
|
|
expect(JSON::Validator.fully_validate(dashboard_schema, result[:dashboard])).to be_empty
|
2019-04-16 03:01:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'caches the dashboard for subsequent calls' do
|
|
|
|
expect(YAML).to receive(:load_file).once.and_call_original
|
|
|
|
|
2019-04-17 07:37:42 -04:00
|
|
|
described_class.new(project, environment).get_dashboard
|
|
|
|
described_class.new(project, environment).get_dashboard
|
2019-04-16 03:01:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|