diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-20 15:08:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-20 15:08:44 +0000 |
commit | b9bac6dbf78a5a7976fba14aaeef96bdeb0da612 (patch) | |
tree | ffe277b562256f718b0818e8fd3c8fd8766d0269 /spec/models | |
parent | 8c4198cbe631278e87fee04157d23494fbb80cdb (diff) | |
download | gitlab-ce-b9bac6dbf78a5a7976fba14aaeef96bdeb0da612.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/clusters/applications/prometheus_spec.rb | 35 | ||||
-rw-r--r-- | spec/models/environment_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/serverless/domain_cluster_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/serverless/domain_spec.rb | 97 |
4 files changed, 124 insertions, 24 deletions
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index ba344a234b8..04e4d261b1c 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -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 @@ -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 diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 72143d69fc8..48cabd4301c 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -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) diff --git a/spec/models/serverless/domain_cluster_spec.rb b/spec/models/serverless/domain_cluster_spec.rb index bd645b7d0aa..f5e1eb304a1 100644 --- a/spec/models/serverless/domain_cluster_spec.rb +++ b/spec/models/serverless/domain_cluster_spec.rb @@ -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 @@ -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) @@ -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 diff --git a/spec/models/serverless/domain_spec.rb b/spec/models/serverless/domain_spec.rb new file mode 100644 index 00000000000..ba54e05b4e3 --- /dev/null +++ b/spec/models/serverless/domain_spec.rb @@ -0,0 +1,97 @@ +# 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 |