debian-mirror-gitlab/spec/models/clusters/applications/cert_manager_spec.rb

98 lines
2.9 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2019-02-15 15:39:39 +05:30
require 'rails_helper'
describe Clusters::Applications::CertManager do
let(:cert_manager) { create(:clusters_applications_cert_managers) }
include_examples 'cluster application core specs', :clusters_applications_cert_managers
2019-03-02 22:35:43 +05:30
include_examples 'cluster application status specs', :clusters_applications_cert_managers
include_examples 'cluster application version specs', :clusters_applications_cert_managers
include_examples 'cluster application initial status specs'
2019-02-15 15:39:39 +05:30
2019-07-31 22:56:46 +05:30
describe '#can_uninstall?' do
subject { cert_manager.can_uninstall? }
it { is_expected.to be_falsey }
end
2019-02-15 15:39:39 +05:30
describe '#install_command' do
2019-07-07 11:18:12 +05:30
let(:cert_email) { 'admin@example.com' }
let(:cluster_issuer_file) do
file_contents = <<~EOF
---
apiVersion: certmanager.k8s.io/v1alpha1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: #{cert_email}
privateKeySecretRef:
name: letsencrypt-prod
http01: {}
EOF
{ "cluster_issuer.yaml": file_contents }
end
2019-02-15 15:39:39 +05:30
subject { cert_manager.install_command }
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) }
2019-07-07 11:18:12 +05:30
it 'is initialized with cert_manager arguments' do
2019-02-15 15:39:39 +05:30
expect(subject.name).to eq('certmanager')
expect(subject.chart).to eq('stable/cert-manager')
expect(subject.version).to eq('v0.5.2')
expect(subject).to be_rbac
expect(subject.files).to eq(cert_manager.files.merge(cluster_issuer_file))
expect(subject.postinstall).to eq(['/usr/bin/kubectl create -f /data/helm/certmanager/config/cluster_issuer.yaml'])
end
context 'for a specific user' do
2019-07-07 11:18:12 +05:30
let(:cert_email) { 'abc@xyz.com' }
2019-02-15 15:39:39 +05:30
before do
2019-07-07 11:18:12 +05:30
cert_manager.email = cert_email
2019-02-15 15:39:39 +05:30
end
2019-07-07 11:18:12 +05:30
it 'uses his/her email to register issuer with certificate provider' do
2019-02-15 15:39:39 +05:30
expect(subject.files).to eq(cert_manager.files.merge(cluster_issuer_file))
end
end
context 'on a non rbac enabled cluster' do
before do
cert_manager.cluster.platform_kubernetes.abac!
end
it { is_expected.not_to be_rbac }
end
context 'application failed to install previously' do
let(:cert_manager) { create(:clusters_applications_cert_managers, :errored, version: '0.0.1') }
2019-07-07 11:18:12 +05:30
it 'is initialized with the locked version' do
2019-02-15 15:39:39 +05:30
expect(subject.version).to eq('v0.5.2')
end
end
end
describe '#files' do
let(:application) { cert_manager }
let(:values) { subject[:'values.yaml'] }
subject { application.files }
2019-07-07 11:18:12 +05:30
it 'includes cert_manager specific keys in the values.yaml file' do
2019-02-15 15:39:39 +05:30
expect(values).to include('ingressShim')
end
end
describe 'validations' do
it { is_expected.to validate_presence_of(:email) }
end
end