diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-09 22:24:24 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-11 23:07:12 +0200 |
commit | 693602d957b2bb48a5270d249a2e2708c03bd803 (patch) | |
tree | f68006a9b15cf54fde168ae9997796994bb60ed5 /spec/lib/gitlab/prometheus | |
parent | 4f824d2aecf4fec46febd767fa7f7d747c732112 (diff) | |
download | gitlab-ce-693602d957b2bb48a5270d249a2e2708c03bd803.tar.gz |
Keep presentation logic in one place and remove unecessary arguments.
+ fix tests
Diffstat (limited to 'spec/lib/gitlab/prometheus')
-rw-r--r-- | spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb b/spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb index c69cd180547..e739005ba83 100644 --- a/spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb @@ -1,28 +1,32 @@ require 'spec_helper' describe Gitlab::Prometheus::Queries::DeploymentQuery, lib: true do - let(:environment) { create(:environment) } + let(:environment) { create(:environment, slug: 'environment-slug') } let(:deployment) { create(:deployment, environment: environment) } let(:client) { double('prometheus_client') } subject { described_class.new(client) } + around do |example| + Timecop.freeze { example.run } + end + it 'sends appropriate queries to prometheus' do start_time = (deployment.created_at - 30.minutes).to_f stop_time = (deployment.created_at + 30.minutes).to_f - expect(client).to receive(:query_range).with('avg(container_memory_usage_bytes{container_name!="POD",environment="environment1"}) / 2^20', + expect(client).to receive(:query_range).with('avg(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}) / 2^20', start: start_time, stop: stop_time) - expect(client).to receive(:query).with('avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment1"}[30m]))', + expect(client).to receive(:query).with('avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}[30m]))', time: deployment.created_at.to_f) - expect(client).to receive(:query).with('avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment1"}[30m]))', + expect(client).to receive(:query).with('avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}[30m]))', time: stop_time) - expect(client).to receive(:query_range).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment1"}[2m])) * 100', + expect(client).to receive(:query_range).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[2m])) * 100', start: start_time, stop: stop_time) - expect(client).to receive(:query).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment1"}[30m])) * 100', + expect(client).to receive(:query).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100', time: deployment.created_at.to_f) - expect(client).to receive(:query).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment1"}[30m])) * 100', + expect(client).to receive(:query).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100', time: stop_time) expect(subject.query(deployment.id)).to eq(memory_values: nil, memory_before: nil, memory_after: nil, |