diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-19 00:09:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-19 00:09:57 +0300 |
commit | bfce95a4c5e9d71ed523f48f3fb901d2b7af60f7 (patch) | |
tree | 6bada22ff3863edec03f928f8edcf19c6e7107f1 /spec/models/performance_monitoring | |
parent | 85f7fa54f404f28b0f351c2be0f7a6e9d74fe65f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/performance_monitoring')
-rw-r--r-- | spec/models/performance_monitoring/prometheus_dashboard_spec.rb | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/spec/models/performance_monitoring/prometheus_dashboard_spec.rb b/spec/models/performance_monitoring/prometheus_dashboard_spec.rb index 61174a7d0c5..ca4572ac094 100644 --- a/spec/models/performance_monitoring/prometheus_dashboard_spec.rb +++ b/spec/models/performance_monitoring/prometheus_dashboard_spec.rb @@ -219,20 +219,31 @@ RSpec.describe PerformanceMonitoring::PrometheusDashboard do end describe '#schema_validation_warnings' do + let_it_be(:project) { create(:project) } + let_it_be(:environment) { create(:environment, project: project) } + let(:path) { '.gitlab/dashboards/test.yml' } + + subject(:schema_validation_warnings) { described_class.new(json_content.merge(path: path, environment: environment)).schema_validation_warnings } + + before do + allow(Gitlab::Metrics::Dashboard::Finder).to receive(:find_raw).with(project, dashboard_path: path).and_return(json_content) + end + context 'when schema is valid' do it 'returns nil' do - expect(described_class).to receive(:from_json) - expect(described_class.new.schema_validation_warnings).to be_nil + expect(Gitlab::Metrics::Dashboard::Validator).to receive(:errors).with(json_content, dashboard_path: path, project: project).and_return([]) + + expect(schema_validation_warnings).to eq [] end end context 'when schema is invalid' do it 'returns array with errors messages' do - instance = described_class.new - instance.errors.add(:test, 'test error') + error = ::Gitlab::Metrics::Dashboard::Validator::Errors::SchemaValidationError.new + + expect(Gitlab::Metrics::Dashboard::Validator).to receive(:errors).with(json_content, dashboard_path: path, project: project).and_return([error]) - expect(described_class).to receive(:from_json).and_raise(ActiveModel::ValidationError.new(instance)) - expect(described_class.new.schema_validation_warnings).to eq ['test: test error'] + expect(schema_validation_warnings).to eq [error.message] end end end |