diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-05 20:43:30 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-05 20:43:30 +0300 |
commit | a3eb8264f31a79fc05113df4276d7dcf4e0bad75 (patch) | |
tree | 51eb98ef2e43b7a97aa71db60e26742d808be85a /spec/lib/gitlab/prometheus | |
parent | eccc187a70a6745ca02211648814c89ff390dfa3 (diff) |
Refactor Metric tests to use more common code
Diffstat (limited to 'spec/lib/gitlab/prometheus')
-rw-r--r-- | spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb | 20 |
1 files changed, 13 insertions, 7 deletions
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 390fff568cc..34f11205878 100644 --- a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do include Prometheus::MatchedMetricsQueryHelper + include Prometheus::MetricBuilders let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } let(:metric_class) { Gitlab::Prometheus::Metric } @@ -83,30 +84,35 @@ describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do end end - context 'with two groups where only one metric is found' do + context 'with two groups where metrics are found in each group' do + let(:second_metric_group) { simple_metric_group(name: 'nameb', metrics: simple_metrics(added_metric_name: 'metric_c')) } + before do - allow(metric_group_class).to receive(:all).and_return([simple_metric_group, - simple_metric_group('nameb', simple_metrics('metric_c'))]) + allow(metric_group_class).to receive(:all).and_return([simple_metric_group, second_metric_group]) allow(client).to receive(:label_values).and_return('metric_c') end - context 'both metrics in the group pass requirements' do + context 'all metrics in both groups pass requirements' do before do allow(client).to receive(:series).and_return(series_info_with_environment('metric_c')) end it 'responds with one metrics as active and no missing requiremens' do - expect(subject.query).to eq([{ group: 'nameb', priority: 1, active_metrics: 1, metrics_missing_requirements: 0 }]) + expect(subject.query).to eq([ + { group: 'name', priority: 1, active_metrics: 1, metrics_missing_requirements: 0 }, + { group: 'nameb', priority: 1, active_metrics: 2, metrics_missing_requirements: 0 }]) end end - context 'no metris in group pass requirements' do + context 'no metrics in groups pass requirements' do before do allow(client).to receive(:series).and_return(series_info_without_environment) end it 'responds with one metrics as active and no missing requiremens' do - expect(subject.query).to eq([{ group: 'nameb', priority: 1, active_metrics: 0, metrics_missing_requirements: 1 }]) + expect(subject.query).to eq([ + { group: 'name', priority: 1, active_metrics: 0, metrics_missing_requirements: 1 }, + { group: 'nameb', priority: 1, active_metrics: 0, metrics_missing_requirements: 2 }]) end end end |