summaryrefslogtreecommitdiff
path: root/spec/models/clusters/applications
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-24 09:09:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-24 09:09:25 +0000
commit6f7881ee9dcec34141a8f34fc814b56b366d2b48 (patch)
tree25f72a06874b32b1049b79a9d7f4f1b7bca43b9b /spec/models/clusters/applications
parent8c8bf44fa64f98114f7439f751c92d59a44b3218 (diff)
downloadgitlab-ce-6f7881ee9dcec34141a8f34fc814b56b366d2b48.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/clusters/applications')
-rw-r--r--spec/models/clusters/applications/ingress_spec.rb58
-rw-r--r--spec/models/clusters/applications/prometheus_spec.rb45
2 files changed, 91 insertions, 12 deletions
diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb
index ba5f48ce6b3..64d667f40f6 100644
--- a/spec/models/clusters/applications/ingress_spec.rb
+++ b/spec/models/clusters/applications/ingress_spec.rb
@@ -21,26 +21,60 @@ describe Clusters::Applications::Ingress do
describe '#can_uninstall?' do
subject { ingress.can_uninstall? }
- it 'returns true if external ip is set and no application exists' do
- ingress.external_ip = 'IP'
+ context 'with jupyter installed' do
+ before do
+ create(:clusters_applications_jupyter, :installed, cluster: ingress.cluster)
+ end
- is_expected.to be_truthy
- end
+ it 'returns false if external_ip_or_hostname? is true' do
+ ingress.external_ip = 'IP'
- it 'returns false if application_jupyter_nil_or_installable? is false' do
- create(:clusters_applications_jupyter, :installed, cluster: ingress.cluster)
+ is_expected.to be_falsey
+ end
- is_expected.to be_falsey
+ it 'returns false if external_ip_or_hostname? is false' do
+ is_expected.to be_falsey
+ end
end
- it 'returns false if application_elastic_stack_nil_or_installable? is false' do
- create(:clusters_applications_elastic_stack, :installed, cluster: ingress.cluster)
+ context 'with jupyter installable' do
+ before do
+ create(:clusters_applications_jupyter, :installable, cluster: ingress.cluster)
+ end
+
+ it 'returns true if external_ip_or_hostname? is true' do
+ ingress.external_ip = 'IP'
+
+ is_expected.to be_truthy
+ end
- is_expected.to be_falsey
+ it 'returns false if external_ip_or_hostname? is false' do
+ is_expected.to be_falsey
+ end
end
- it 'returns false if external_ip_or_hostname? is false' do
- is_expected.to be_falsey
+ context 'with jupyter nil' do
+ it 'returns false if external_ip_or_hostname? is false' do
+ is_expected.to be_falsey
+ end
+
+ context 'if external_ip_or_hostname? is true' do
+ context 'with IP' do
+ before do
+ ingress.external_ip = 'IP'
+ end
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'with hostname' do
+ before do
+ ingress.external_hostname = 'example.com'
+ end
+
+ it { is_expected.to be_truthy }
+ end
+ end
end
end
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) }