summaryrefslogtreecommitdiff
path: root/spec/models/clusters/applications
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-12-19 21:50:12 +1300
committerThong Kuah <tkuah@gitlab.com>2019-01-15 10:03:08 +1300
commit8296ff580c2bb1b2a9ee07193f79f66fd6444de0 (patch)
treec101388d589cee84b116974e47046c0f90ebe6d6 /spec/models/clusters/applications
parent4a6c7661edae664a7f6366201d017e24d8f42026 (diff)
downloadgitlab-ce-8296ff580c2bb1b2a9ee07193f79f66fd6444de0.tar.gz
Port generic upgrade functionality to CE55544-port-upgrade-command
Port from EE generic upgrade related functionality used to upgrade Helm applications Remove memoization which could be incorrect It looks like we are memoizing without regard to the method's argument so this could result in an incorrect upgrade_command Remove `const_get` indirection now we are no longer in EE
Diffstat (limited to 'spec/models/clusters/applications')
-rw-r--r--spec/models/clusters/applications/prometheus_spec.rb97
1 files changed, 97 insertions, 0 deletions
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb
index de6b844023a..e50ba67c493 100644
--- a/spec/models/clusters/applications/prometheus_spec.rb
+++ b/spec/models/clusters/applications/prometheus_spec.rb
@@ -90,6 +90,24 @@ describe Clusters::Applications::Prometheus do
expect(application).not_to be_ready
end
+
+ it 'returns true when updating' do
+ application = build(:clusters_applications_prometheus, :updating, cluster: cluster)
+
+ expect(application).to be_ready
+ end
+
+ it 'returns true when updated' do
+ application = build(:clusters_applications_prometheus, :updated, cluster: cluster)
+
+ expect(application).to be_ready
+ end
+
+ it 'returns true when errored' do
+ application = build(:clusters_applications_prometheus, :update_errored, cluster: cluster)
+
+ expect(application).to be_ready
+ end
end
describe '#prometheus_client' do
@@ -197,6 +215,46 @@ describe Clusters::Applications::Prometheus do
end
end
+ describe '#upgrade_command' do
+ let(:prometheus) { build(:clusters_applications_prometheus) }
+ let(:values) { prometheus.values }
+
+ it 'returns an instance of Gitlab::Kubernetes::Helm::GetCommand' do
+ expect(prometheus.upgrade_command(values)).to be_an_instance_of(::Gitlab::Kubernetes::Helm::UpgradeCommand)
+ end
+
+ it 'should be initialized with 3 arguments' do
+ command = prometheus.upgrade_command(values)
+
+ expect(command.name).to eq('prometheus')
+ expect(command.chart).to eq('stable/prometheus')
+ expect(command.version).to eq('6.7.3')
+ expect(command.files).to eq(prometheus.files)
+ end
+ end
+
+ describe '#update_in_progress?' do
+ context 'when app is updating' do
+ it 'returns true' do
+ cluster = create(:cluster)
+ prometheus_app = build(:clusters_applications_prometheus, :updating, cluster: cluster)
+
+ expect(prometheus_app.update_in_progress?).to be true
+ end
+ end
+ end
+
+ describe '#update_errored?' do
+ context 'when app errored' do
+ it 'returns true' do
+ cluster = create(:cluster)
+ prometheus_app = build(:clusters_applications_prometheus, :update_errored, cluster: cluster)
+
+ expect(prometheus_app.update_errored?).to be true
+ end
+ end
+ end
+
describe '#files' do
let(:application) { create(:clusters_applications_prometheus) }
let(:values) { subject[:'values.yaml'] }
@@ -211,4 +269,43 @@ describe Clusters::Applications::Prometheus do
expect(values).to include('serverFiles')
end
end
+
+ describe '#files_with_replaced_values' do
+ let(:application) { build(:clusters_applications_prometheus) }
+ let(:files) { application.files }
+
+ subject { application.files_with_replaced_values({ hello: :world }) }
+
+ it 'does not modify #files' do
+ expect(subject[:'values.yaml']).not_to eq(files)
+ expect(files[:'values.yaml']).to eq(application.values)
+ end
+
+ it 'returns values.yaml with replaced values' do
+ expect(subject[:'values.yaml']).to eq({ hello: :world })
+ end
+
+ it 'should include cert files' do
+ expect(subject[:'ca.pem']).to be_present
+ expect(subject[:'ca.pem']).to eq(application.cluster.application_helm.ca_cert)
+
+ expect(subject[:'cert.pem']).to be_present
+ expect(subject[:'key.pem']).to be_present
+
+ cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem'])
+ expect(cert.not_after).to be < 60.minutes.from_now
+ end
+
+ context 'when the helm application does not have a ca_cert' do
+ before do
+ application.cluster.application_helm.ca_cert = nil
+ end
+
+ it 'should not include cert files' do
+ expect(subject[:'ca.pem']).not_to be_present
+ expect(subject[:'cert.pem']).not_to be_present
+ expect(subject[:'key.pem']).not_to be_present
+ end
+ end
+ end
end