summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorChris Baumbauer <cab@cabnetworks.net>2018-11-05 23:55:18 -0800
committerChris Baumbauer <cab@cabnetworks.net>2018-11-05 23:55:18 -0800
commit97441486ceb3522fc5d3ff9e52a9d93e07bc8961 (patch)
treebc7774f06c43b3b6131b2e036cd3e1695f0b226c /spec
parent1435fe60752728790544ed07bf4c95fc3ba39efe (diff)
downloadgitlab-ce-97441486ceb3522fc5d3ff9e52a9d93e07bc8961.tar.gz
Fix issue with missing knative cluster role binding, and cleanup tests
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/clusters/applications/helm.rb1
-rw-r--r--spec/lib/gitlab/kubernetes/helm/install_command_spec.rb53
-rw-r--r--spec/models/clusters/applications/knative_spec.rb29
3 files changed, 62 insertions, 21 deletions
diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb
index 3fe088d47cc..ff65c76cf26 100644
--- a/spec/factories/clusters/applications/helm.rb
+++ b/spec/factories/clusters/applications/helm.rb
@@ -58,6 +58,7 @@ FactoryBot.define do
end
factory :clusters_applications_knative, class: Clusters::Applications::Knative do
+ hostname 'example.com'
cluster factory: %i(cluster with_installed_helm provided_by_gcp)
end
diff --git a/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb b/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb
index bbe7cbe05c5..ed879350004 100644
--- a/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb
+++ b/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb
@@ -5,6 +5,8 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
let(:repository) { 'https://repository.example.com' }
let(:rbac) { false }
let(:version) { '1.2.3' }
+ let(:preinstall) { nil }
+ let(:postinstall) { nil }
let(:install_command) do
described_class.new(
@@ -13,7 +15,9 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
rbac: rbac,
files: files,
version: version,
- repository: repository
+ repository: repository,
+ preinstall: preinstall,
+ postinstall: postinstall
)
end
@@ -101,6 +105,53 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
end
end
+ context 'when there is a pre-install script' do
+ let(:preinstall) { ['/bin/date', '/bin/true'] }
+
+ it_behaves_like 'helm commands' do
+ let(:commands) do
+ <<~EOS
+ helm init --client-only >/dev/null
+ helm repo add app-name https://repository.example.com
+ helm repo update >/dev/null
+ #{helm_install_command}
+ EOS
+ end
+
+ let(:helm_install_command) do
+ <<~EOS.strip
+ /bin/date
+ /bin/true
+ helm install chart-name --name app-name --tls --tls-ca-cert /data/helm/app-name/config/ca.pem --tls-cert /data/helm/app-name/config/cert.pem --tls-key /data/helm/app-name/config/key.pem --version 1.2.3 --namespace gitlab-managed-apps -f /data/helm/app-name/config/values.yaml >/dev/null
+ EOS
+ end
+ end
+ end
+
+ context 'when there is a post-install script' do
+ let(:postinstall) { ['/bin/date', "/bin/false\n"] }
+
+ it_behaves_like 'helm commands' do
+ let(:commands) do
+ <<~EOS
+ helm init --client-only >/dev/null
+ helm repo add app-name https://repository.example.com
+ helm repo update >/dev/null
+ #{helm_install_command}
+ EOS
+ end
+
+ let(:helm_install_command) do
+ <<~EOS.strip
+ helm install chart-name --name app-name --tls --tls-ca-cert /data/helm/app-name/config/ca.pem --tls-cert /data/helm/app-name/config/cert.pem --tls-key /data/helm/app-name/config/key.pem --version 1.2.3 --namespace gitlab-managed-apps -f /data/helm/app-name/config/values.yaml >/dev/null
+
+ /bin/date
+ /bin/false
+ EOS
+ end
+ end
+ end
+
context 'when there is no ca.pem file' do
let(:files) { { 'file.txt': 'some content' } }
diff --git a/spec/models/clusters/applications/knative_spec.rb b/spec/models/clusters/applications/knative_spec.rb
index 6d72e3fba16..7849e29d546 100644
--- a/spec/models/clusters/applications/knative_spec.rb
+++ b/spec/models/clusters/applications/knative_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe Clusters::Applications::Knative do
- let(:knative) { create(:clusters_applications_knative, hostname: 'example.com') }
+ let(:knative) { create(:clusters_applications_knative) }
include_examples 'cluster application core specs', :clusters_applications_knative
include_examples 'cluster application status specs', :clusters_applications_knative
@@ -47,7 +47,9 @@ describe Clusters::Applications::Knative do
describe '#install_command' do
subject { knative.install_command }
- it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) }
+ it 'should be an instance of Helm::InstallCommand' do
+ expect(subject).to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand)
+ end
it 'should be initialized with knative arguments' do
expect(subject.name).to eq('knative')
@@ -55,14 +57,6 @@ describe Clusters::Applications::Knative do
expect(subject.version).to eq('0.1.3')
expect(subject.files).to eq(knative.files)
end
-
- context 'application failed to install previously' do
- let(:knative) { create(:clusters_applications_knative, :errored, version: 'knative', hostname: 'example.com') }
-
- it 'should be initialized with the locked version' do
- expect(subject.version).to eq('0.1.3')
- end
- end
end
describe '#files' do
@@ -71,7 +65,7 @@ describe Clusters::Applications::Knative do
subject { application.files }
- it 'should include knative valid keys in values' do
+ it 'should include knative specific keys in the values.yaml file' do
expect(values).to include('domain')
end
@@ -80,20 +74,15 @@ describe Clusters::Applications::Knative 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
+ it 'should not include cert files when there is no ca_cert entry' do
+ expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem')
end
end
- it 'should include cert files' do
- expect(subject[:'ca.pem']).to be_present
+ it 'should include cert files when there is a ca_cert entry' do
+ expect(subject).to include(:'ca.pem', :'cert.pem', :'key.pem')
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