Commit c2818d6b authored by rpereira2's avatar rpereira2 Committed by syasonik

Add schema validation spec

Validate the schema of the dashboard that is loaded by
Gitlab::MetricsDashboard::Service.
parent 4a9002ce
{
"type": "object",
"required": [
"dashboard",
"order",
"panel_groups"
],
"properties": {
"dashboard": { "type": "string" },
"order": { "type": "number" },
"panel_groups": {
"type": "array",
"items": { "$ref": "spec/fixtures/lib/gitlab/metrics_dashboard/schemas/panel_groups.json" }
}
},
"additionalProperties": false
}
{
"type": "object",
"required": [
"unit",
"label"
],
"properties": {
"id": { "type": "string" },
"query_range": { "type": "string" },
"query": { "type": "string" },
"unit": { "type": "string" },
"label": { "type": "string" },
"track": { "type": "string" }
},
"additionalProperties": false
}
{
"type": "object",
"required": [
"group",
"priority",
"panels"
],
"properties": {
"group": { "type": "string" },
"priority": { "type": "number" },
"panels": {
"type": "array",
"items": { "$ref": "panels.json" }
}
},
"additionalProperties": false
}
{
"type": "object",
"required": [
"title",
"y_label",
"weight",
"metrics"
],
"properties": {
"title": { "type": "string" },
"type": { "type": "string" },
"y_label": { "type": "string" },
"weight": { "type": "number" },
"metrics": {
"type": "array",
"items": { "$ref": "metrics.json" }
}
},
"additionalProperties": false
}
...@@ -6,14 +6,15 @@ describe Gitlab::MetricsDashboard::Service, :use_clean_rails_memory_store_cachin ...@@ -6,14 +6,15 @@ describe Gitlab::MetricsDashboard::Service, :use_clean_rails_memory_store_cachin
let(:project) { build(:project) } let(:project) { build(:project) }
describe 'get_dashboard' do describe 'get_dashboard' do
let(:dashboard_schema) { JSON.parse(fixture_file('lib/gitlab/metrics_dashboard/schemas/dashboard.json')) }
it 'returns a json representation of the environment dashboard' do it 'returns a json representation of the environment dashboard' do
result = described_class.new(project).get_dashboard result = described_class.new(project).get_dashboard
expect(result.keys).to contain_exactly(:dashboard, :status) expect(result.keys).to contain_exactly(:dashboard, :status)
expect(result[:status]).to eq(:success) expect(result[:status]).to eq(:success)
expect(result[:dashboard]).to include('dashboard', 'order', 'panel_groups') expect(JSON::Validator.fully_validate(dashboard_schema, result[:dashboard])).to be_empty
expect(result[:dashboard]['panel_groups']).to all( include('group', 'priority', 'panels') )
end end
it 'caches the dashboard for subsequent calls' do it 'caches the dashboard for subsequent calls' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment