Skip to content
Snippets Groups Projects
Commit b9bac6db authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 8c4198cb
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -274,7 +274,8 @@ describe Clusters::Applications::Prometheus do
subject { application.files_with_replaced_values({ hello: :world }) }
 
it 'does not modify #files' do
expect(subject[:'values.yaml']).not_to eq(files)
expect(subject[:'values.yaml']).not_to eq(files[:'values.yaml'])
expect(files[:'values.yaml']).to eq(application.values)
end
 
Loading
Loading
@@ -282,27 +283,17 @@ describe Clusters::Applications::Prometheus do
expect(subject[:'values.yaml']).to eq({ hello: :world })
end
 
it 'includes 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 'does 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
it 'uses values from #files, except for values.yaml' do
allow(application).to receive(:files).and_return({
'values.yaml': 'some value specific to files',
'file_a.txt': 'file_a',
'file_b.txt': 'file_b'
})
expect(subject.except(:'values.yaml')).to eq({
'file_a.txt': 'file_a',
'file_b.txt': 'file_b'
})
end
end
 
Loading
Loading
Loading
Loading
@@ -1264,6 +1264,14 @@ describe Environment, :use_clean_rails_memory_store_caching do
end
end
 
describe '.for_id_and_slug' do
subject { described_class.for_id_and_slug(environment.id, environment.slug) }
let(:environment) { create(:environment) }
it { is_expected.not_to be_nil }
end
describe '.find_or_create_by_name' do
it 'finds an existing environment if it exists' do
env = create(:environment)
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ describe ::Serverless::DomainCluster do
it { is_expected.to validate_presence_of(:knative) }
 
it { is_expected.to validate_presence_of(:uuid) }
it { is_expected.to validate_length_of(:uuid).is_equal_to(Gitlab::Serverless::Domain::UUID_LENGTH) }
it { is_expected.to validate_length_of(:uuid).is_equal_to(::Serverless::Domain::UUID_LENGTH) }
it { is_expected.to validate_uniqueness_of(:uuid) }
 
it 'validates that uuid has only hex characters' do
Loading
Loading
@@ -31,7 +31,7 @@ describe ::Serverless::DomainCluster do
context 'when nil' do
it 'generates a value by default' do
attributes = build(:serverless_domain_cluster).attributes.merge(uuid: nil)
expect(Gitlab::Serverless::Domain).to receive(:generate_uuid).and_call_original
expect(::Serverless::Domain).to receive(:generate_uuid).and_call_original
 
subject = Serverless::DomainCluster.new(attributes)
 
Loading
Loading
@@ -47,6 +47,10 @@ describe ::Serverless::DomainCluster do
end
end
 
describe 'cluster' do
it { is_expected.to respond_to(:cluster) }
end
describe 'domain' do
it { is_expected.to respond_to(:domain) }
end
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe ::Serverless::Domain do
let(:function_name) { 'test-function' }
let(:pages_domain_name) { 'serverless.gitlab.io' }
let(:pages_domain) { create(:pages_domain, :instance_serverless, domain: pages_domain_name) }
let!(:serverless_domain_cluster) { create(:serverless_domain_cluster, uuid: 'abcdef12345678', pages_domain: pages_domain) }
let(:valid_cluster_uuid) { 'aba1cdef123456f278' }
let(:invalid_cluster_uuid) { 'aba1cdef123456f178' }
let!(:environment) { create(:environment, name: 'test') }
let(:valid_uri) { "https://#{function_name}-#{valid_cluster_uuid}#{"%x" % environment.id}-#{environment.slug}.#{pages_domain_name}" }
let(:valid_fqdn) { "#{function_name}-#{valid_cluster_uuid}#{"%x" % environment.id}-#{environment.slug}.#{pages_domain_name}" }
let(:invalid_uri) { "https://#{function_name}-#{invalid_cluster_uuid}#{"%x" % environment.id}-#{environment.slug}.#{pages_domain_name}" }
shared_examples 'a valid Domain' do
describe '#uri' do
it 'matches valid URI' do
expect(subject.uri.to_s).to eq valid_uri
end
end
describe '#function_name' do
it 'returns function_name' do
expect(subject.function_name).to eq function_name
end
end
describe '#serverless_domain_cluster' do
it 'returns serverless_domain_cluster' do
expect(subject.serverless_domain_cluster).to eq serverless_domain_cluster
end
end
describe '#environment' do
it 'returns environment' do
expect(subject.environment).to eq environment
end
end
end
describe '.new' do
context 'with valid arguments' do
subject do
described_class.new(
function_name: function_name,
serverless_domain_cluster: serverless_domain_cluster,
environment: environment
)
end
it_behaves_like 'a valid Domain'
end
context 'with invalid arguments' do
subject do
described_class.new(
function_name: function_name,
environment: environment
)
end
it { is_expected.not_to be_valid }
end
context 'with nil cluster argument' do
subject do
described_class.new(
function_name: function_name,
serverless_domain_cluster: nil,
environment: environment
)
end
it { is_expected.not_to be_valid }
end
end
describe '.generate_uuid' do
it 'has 14 characters' do
expect(described_class.generate_uuid.length).to eq(described_class::UUID_LENGTH)
end
it 'consists of only hexadecimal characters' do
expect(described_class.generate_uuid).to match(/\A\h+\z/)
end
it 'uses random characters' do
uuid = 'abcd1234567890'
expect(SecureRandom).to receive(:hex).with(described_class::UUID_LENGTH / 2).and_return(uuid)
expect(described_class.generate_uuid).to eq(uuid)
end
end
end
Loading
Loading
@@ -28,22 +28,46 @@ RSpec.shared_examples 'cluster application helm specs' do |application_name|
describe '#files' do
subject { application.files }
 
context 'when the helm application does not have a ca_cert' do
context 'managed_apps_local_tiller feature flag is disabled' do
before do
application.cluster.application_helm.ca_cert = nil
stub_feature_flags(managed_apps_local_tiller: false)
end
 
it 'does not include cert files when there is no ca_cert entry' do
expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem')
context 'when the helm application does not have a ca_cert' do
before do
application.cluster.application_helm.ca_cert = nil
end
it 'does 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 'includes 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)
cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem'])
expect(cert.not_after).to be < 60.minutes.from_now
end
end
 
it 'includes 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)
context 'managed_apps_local_tiller feature flag is enabled' do
before do
stub_feature_flags(managed_apps_local_tiller: true)
end
it 'does not include cert files' do
expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem')
end
context 'when cluster does not have helm installed' do
let(:application) { create(application_name, :no_helm_installed) }
 
cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem'])
expect(cert.not_after).to be < 60.minutes.from_now
it 'does not include cert files' do
expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem')
end
end
end
end
end
Loading
Loading
@@ -48,14 +48,44 @@ RSpec.shared_examples 'cluster application status specs' do |application_name|
expect(subject).to be_installed
end
 
it 'updates helm version' do
subject.cluster.application_helm.update!(version: '1.2.3')
context 'managed_apps_local_tiller feature flag disabled' do
before do
stub_feature_flags(managed_apps_local_tiller: false)
end
 
subject.make_installed!
it 'updates helm version' do
subject.cluster.application_helm.update!(version: '1.2.3')
 
subject.cluster.application_helm.reload
subject.make_installed!
 
expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION)
subject.cluster.application_helm.reload
expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION)
end
end
context 'managed_apps_local_tiller feature flag enabled' do
before do
stub_feature_flags(managed_apps_local_tiller: true)
end
it 'does not update the helm version' do
subject.cluster.application_helm.update!(version: '1.2.3')
expect do
subject.make_installed!
subject.cluster.application_helm.reload
end.not_to change { subject.cluster.application_helm.version }
end
context 'the cluster has no helm installed' do
subject { create(application_name, :installing, :no_helm_installed) }
it 'runs without errors' do
expect { subject.make_installed! }.not_to raise_error
end
end
end
 
it 'sets the correct version of the application' do
Loading
Loading
@@ -77,14 +107,44 @@ RSpec.shared_examples 'cluster application status specs' do |application_name|
expect(subject).to be_updated
end
 
it 'updates helm version' do
subject.cluster.application_helm.update!(version: '1.2.3')
context 'managed_apps_local_tiller feature flag disabled' do
before do
stub_feature_flags(managed_apps_local_tiller: false)
end
 
subject.make_installed!
it 'updates helm version' do
subject.cluster.application_helm.update!(version: '1.2.3')
 
subject.cluster.application_helm.reload
subject.make_installed!
 
expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION)
subject.cluster.application_helm.reload
expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION)
end
end
context 'managed_apps_local_tiller feature flag enabled' do
before do
stub_feature_flags(managed_apps_local_tiller: true)
end
it 'does not update the helm version' do
subject.cluster.application_helm.update!(version: '1.2.3')
expect do
subject.make_installed!
subject.cluster.application_helm.reload
end.not_to change { subject.cluster.application_helm.version }
end
context 'the cluster has no helm installed' do
subject { create(application_name, :updating, :no_helm_installed) }
it 'runs without errors' do
expect { subject.make_installed! }.not_to raise_error
end
end
end
 
it 'updates the version of the application' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment