diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-20 18:08:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-20 18:08:44 +0300 |
commit | b9bac6dbf78a5a7976fba14aaeef96bdeb0da612 (patch) | |
tree | ffe277b562256f718b0818e8fd3c8fd8766d0269 /spec/models/serverless | |
parent | 8c4198cbe631278e87fee04157d23494fbb80cdb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/serverless')
-rw-r--r-- | spec/models/serverless/domain_cluster_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/serverless/domain_spec.rb | 97 |
2 files changed, 103 insertions, 2 deletions
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 |