summaryrefslogtreecommitdiff
path: root/spec/models/clusters/applications/prometheus_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/clusters/applications/prometheus_spec.rb')
-rw-r--r--spec/models/clusters/applications/prometheus_spec.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb
index ecb87910d2d..ce341e67c14 100644
--- a/spec/models/clusters/applications/prometheus_spec.rb
+++ b/spec/models/clusters/applications/prometheus_spec.rb
@@ -39,6 +39,19 @@ describe Clusters::Applications::Prometheus do
end
end
+ describe 'transition to updating' do
+ let(:project) { create(:project) }
+ let(:cluster) { create(:cluster, projects: [project]) }
+
+ subject { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
+
+ it 'sets last_update_started_at to now' do
+ Timecop.freeze do
+ expect { subject.make_updating }.to change { subject.reload.last_update_started_at }.to be_within(1.second).of(Time.now)
+ end
+ end
+ end
+
describe '#can_uninstall?' do
let(:prometheus) { create(:clusters_applications_prometheus) }
@@ -331,6 +344,38 @@ describe Clusters::Applications::Prometheus do
end
end
+ describe '#updated_since?' do
+ let(:cluster) { create(:cluster) }
+ let(:prometheus_app) { build(:clusters_applications_prometheus, cluster: cluster) }
+ let(:timestamp) { Time.now - 5.minutes }
+
+ around do |example|
+ Timecop.freeze { example.run }
+ end
+
+ before do
+ prometheus_app.last_update_started_at = Time.now
+ end
+
+ context 'when app does not have status failed' do
+ it 'returns true when last update started after the timestamp' do
+ expect(prometheus_app.updated_since?(timestamp)).to be true
+ end
+
+ it 'returns false when last update started before the timestamp' do
+ expect(prometheus_app.updated_since?(Time.now + 5.minutes)).to be false
+ end
+ end
+
+ context 'when app has status failed' do
+ it 'returns false when last update started after the timestamp' do
+ prometheus_app.status = 6
+
+ expect(prometheus_app.updated_since?(timestamp)).to be false
+ end
+ end
+ end
+
describe 'alert manager token' do
subject { create(:clusters_applications_prometheus) }