From cf4aeafa6f3baaec7652f486cd04b7170dde9fbf Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 5 Jun 2017 14:42:53 +0200 Subject: [PATCH] Test Partial additional query response --- .../queries/additional_metrics_query_spec.rb | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb index 617028cde37..2291c4d67bb 100644 --- a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb @@ -24,12 +24,12 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do context 'some queries 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([]) + allow(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) + allow(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) + allow(client).to receive(:query_range).with('query_range_empty', any_args).and_return([]) end - it 'return results only for queries with results' do + it 'return group data only for queries with results' do expected = [ { group: 'name', @@ -61,14 +61,13 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do allow(client).to receive(:label_values).and_return(metric_names) end - context 'some queries return results' do + context 'both queries 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) + allow(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) + allow(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) end - it 'return results only for queries with results' do - puts query_result + it 'return group data both queries' do expected = [ { group: 'group_a', @@ -117,5 +116,42 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do expect(query_result).to eq(expected) end end + + context 'one query returns result' do + before do + allow(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) + allow(client).to receive(:query_range).with('query_range_b', any_args).and_return([]) + end + + it 'queries using specific time' do + expect(client).to receive(:query_range).with(anything, start: 8.hours.ago.to_f, stop: Time.now.to_f) + + expect(query_result).not_to be_nil + end + + it 'return group data only for query with results' do + expected = [ + { + group: 'group_a', + priority: 1, + metrics: [ + { + title: 'title', + weight: nil, + y_label: 'Values', + queries: [ + { + query_range: 'query_range_a', + result: query_range_result + } + ] + } + ] + } + ] + + expect(query_result).to eq(expected) + end + end end end