From ae5268ce8cc533be4086a11d9d89fa726136d59d Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 5 Jun 2017 11:32:56 +0200 Subject: Additional Metrics tests --- .../queries/additional_metrics_query_spec.rb | 49 ++++++++++++++++++++++ .../queries/matched_metrics_query_spec.rb | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb (limited to 'spec/lib/gitlab/prometheus') diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb new file mode 100644 index 00000000000..c7e2dbc12ec --- /dev/null +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do + include Prometheus::AdditionalMetricsQueryHelper + + let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } + let(:metric_class) { Gitlab::Prometheus::Metric } + + let(:client) { double('prometheus_client') } + let(:environment) { create(:environment, slug: 'environment-slug') } + + subject(:query_result) { described_class.new(client).query(environment.id) } + + + context 'with one group where two metrics is found' do + before do + allow(metric_group_class).to receive(:all).and_return([simple_metric_group]) + allow(client).to receive(:label_values).and_return(metric_names) + end + + context 'some querie return results' do + before do + expect(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) + expect(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) + expect(client).to receive(:query_range).with('query_range_empty', any_args).and_return([]) + end + + it 'return results only for queries with results' do + puts query_result + expected = { + group: 'name', + priority: 1, + metrics: + [ + { + title: 'title', weight: nil, y_label: 'Values', queries: + [ + { query_range: 'query_range_a', result: query_range_result }, + { query_range: 'query_range_b', label: 'label', unit: 'unit', result: query_range_result } + ] + } + ] + } + + expect(query_result).to eq([expected]) + end + end + end +end diff --git a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb index d46de56f520..390fff568cc 100644 --- a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb @@ -10,7 +10,7 @@ describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do subject { described_class.new(client) } - context 'with one group where two metrics are found' do + context 'with one group where two metrics is found' do before do allow(metric_group_class).to receive(:all).and_return([simple_metric_group]) allow(client).to receive(:label_values).and_return(metric_names) -- cgit v1.2.1