diff --git a/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/dashboard.json b/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/dashboard.json new file mode 100644 index 0000000000000000000000000000000000000000..4d1ab8615eb82ee24daeb9caad2f957da59bc724 --- /dev/null +++ b/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/dashboard.json @@ -0,0 +1,17 @@ +{ + "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 +} diff --git a/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/metrics.json b/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/metrics.json new file mode 100644 index 0000000000000000000000000000000000000000..4da1004dedd2763b900edbc3162953648087255f --- /dev/null +++ b/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/metrics.json @@ -0,0 +1,16 @@ +{ + "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 +} diff --git a/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/panel_groups.json b/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/panel_groups.json new file mode 100644 index 0000000000000000000000000000000000000000..d7a390adcdc4fdbc4f31a5db38208f0928257e3a --- /dev/null +++ b/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/panel_groups.json @@ -0,0 +1,17 @@ +{ + "type": "object", + "required": [ + "group", + "priority", + "panels" + ], + "properties": { + "group": { "type": "string" }, + "priority": { "type": "number" }, + "panels": { + "type": "array", + "items": { "$ref": "panels.json" } + } + }, + "additionalProperties": false +} diff --git a/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/panels.json b/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/panels.json new file mode 100644 index 0000000000000000000000000000000000000000..1548daacd643d035bef78e3b1b8f48bf7f8fb3b6 --- /dev/null +++ b/spec/fixtures/lib/gitlab/metrics_dashboard/schemas/panels.json @@ -0,0 +1,20 @@ +{ + "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 +} diff --git a/spec/lib/gitlab/metrics_dashboard/service_spec.rb b/spec/lib/gitlab/metrics_dashboard/service_spec.rb index f95748893142d40b70bb3e20e06fb090943cfe56..127fc28bcd60f22297d12f93f6292027cd167707 100644 --- a/spec/lib/gitlab/metrics_dashboard/service_spec.rb +++ b/spec/lib/gitlab/metrics_dashboard/service_spec.rb @@ -6,14 +6,15 @@ describe Gitlab::MetricsDashboard::Service, :use_clean_rails_memory_store_cachin let(:project) { build(:project) } 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 result = described_class.new(project).get_dashboard expect(result.keys).to contain_exactly(:dashboard, :status) expect(result[:status]).to eq(:success) - expect(result[:dashboard]).to include('dashboard', 'order', 'panel_groups') - expect(result[:dashboard]['panel_groups']).to all( include('group', 'priority', 'panels') ) + expect(JSON::Validator.fully_validate(dashboard_schema, result[:dashboard])).to be_empty end it 'caches the dashboard for subsequent calls' do