diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-19 03:07:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-19 03:07:58 +0300 |
commit | 41456efd551f45f569a8c9e70734c88efbbbf0ec (patch) | |
tree | 4ac9d0f1773a8786ba263e88e3d472afcff3d3c1 /spec/models/performance_monitoring/prometheus_metric_spec.rb | |
parent | fe289cff8b1b94020d22f7b3ff1c385a05086b9e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/performance_monitoring/prometheus_metric_spec.rb')
-rw-r--r-- | spec/models/performance_monitoring/prometheus_metric_spec.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/models/performance_monitoring/prometheus_metric_spec.rb b/spec/models/performance_monitoring/prometheus_metric_spec.rb new file mode 100644 index 00000000000..08288e5d993 --- /dev/null +++ b/spec/models/performance_monitoring/prometheus_metric_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe PerformanceMonitoring::PrometheusMetric do + let(:json_content) do + { + "id" => "metric_of_ages", + "unit" => "count", + "label" => "Metric of Ages", + "query_range" => "http_requests_total" + } + end + + describe '.from_json' do + subject { described_class.from_json(json_content) } + + it 'creates a PrometheusMetric object' do + expect(subject).to be_a PerformanceMonitoring::PrometheusMetric + expect(subject.id).to eq(json_content['id']) + expect(subject.unit).to eq(json_content['unit']) + expect(subject.label).to eq(json_content['label']) + expect(subject.query_range).to eq(json_content['query_range']) + end + + describe 'validations' do + context 'when unit is missing' do + before do + json_content['unit'] = nil + end + + subject { described_class.from_json(json_content) } + + it { expect { subject }.to raise_error(ActiveModel::ValidationError) } + end + + context 'when query and query_range is missing' do + before do + json_content['query_range'] = nil + end + + subject { described_class.from_json(json_content) } + + it { expect { subject }.to raise_error(ActiveModel::ValidationError) } + end + + context 'when query_range is missing but query is available' do + before do + json_content['query_range'] = nil + json_content['query'] = 'http_requests_total' + end + + subject { described_class.from_json(json_content) } + + it { is_expected.to be_valid } + end + end + end +end |