Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2017-05-09 07:15:34 +0300
committerJacob Schatz <jschatz@gitlab.com>2017-05-09 07:15:34 +0300
commit0151325dacebb99d54b6effb1d5842c0c712168c (patch)
tree767ea3c8cfeedab5a0ce1921d5842b149ea7c0be /spec/models
parent9ada13d343a4736275d2c026ee980abe5c5e5763 (diff)
Merge request widget redesign
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/deployment_spec.rb27
-rw-r--r--spec/models/project_services/prometheus_service_spec.rb23
2 files changed, 46 insertions, 4 deletions
diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb
index 080ff2f3f43..212fcd884a8 100644
--- a/spec/models/deployment_spec.rb
+++ b/spec/models/deployment_spec.rb
@@ -49,6 +49,33 @@ describe Deployment, models: true do
end
end
+ describe '#metrics' do
+ let(:deployment) { create(:deployment) }
+
+ subject { deployment.metrics(1.hour) }
+
+ context 'metrics are disabled' do
+ it { is_expected.to eq({}) }
+ end
+
+ context 'metrics are enabled' do
+ let(:simple_metrics) do
+ {
+ success: true,
+ metrics: {},
+ last_update: 42
+ }
+ end
+
+ before do
+ allow(deployment.project).to receive_message_chain(:monitoring_service, :metrics)
+ .with(any_args).and_return(simple_metrics)
+ end
+
+ it { is_expected.to eq(simple_metrics.merge(deployment_time: deployment.created_at.utc.to_i)) }
+ end
+ end
+
describe '#stop_action' do
let(:build) { create(:ci_build) }
diff --git a/spec/models/project_services/prometheus_service_spec.rb b/spec/models/project_services/prometheus_service_spec.rb
index f3126bc1e57..82a3e2698c1 100644
--- a/spec/models/project_services/prometheus_service_spec.rb
+++ b/spec/models/project_services/prometheus_service_spec.rb
@@ -47,15 +47,30 @@ describe PrometheusService, models: true, caching: true do
describe '#metrics' do
let(:environment) { build_stubbed(:environment, slug: 'env-slug') }
- subject { service.metrics(environment) }
around do |example|
Timecop.freeze { example.run }
end
- context 'with valid data' do
+ context 'with valid data without time range' do
+ subject { service.metrics(environment) }
+
+ before do
+ stub_reactive_cache(service, prometheus_data, 'env-slug', nil, nil)
+ end
+
+ it 'returns reactive data' do
+ is_expected.to eq(prometheus_data)
+ end
+ end
+
+ context 'with valid data with time range' do
+ let(:t_start) { 1.hour.ago.utc }
+ let(:t_end) { Time.now.utc }
+ subject { service.metrics(environment, timeframe_start: t_start, timeframe_end: t_end) }
+
before do
- stub_reactive_cache(service, prometheus_data, 'env-slug')
+ stub_reactive_cache(service, prometheus_data, 'env-slug', t_start, t_end)
end
it 'returns reactive data' do
@@ -72,7 +87,7 @@ describe PrometheusService, models: true, caching: true do
end
subject do
- service.calculate_reactive_cache(environment.slug)
+ service.calculate_reactive_cache(environment.slug, nil, nil)
end
context 'when service is inactive' do