summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/serverless
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-28 15:08:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-28 15:08:36 +0000
commitfedf978f9aa1909ed7bb3fad767ad120a1c6bd7b (patch)
tree1bd0f0b301ad96feda1910abe34eb89c46cc55cd /spec/lib/gitlab/serverless
parentdb24ab2b72dbff24c201410a0561e929ae7e8061 (diff)
downloadgitlab-ce-fedf978f9aa1909ed7bb3fad767ad120a1c6bd7b.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/serverless')
-rw-r--r--spec/lib/gitlab/serverless/function_uri_spec.rb81
1 files changed, 81 insertions, 0 deletions
diff --git a/spec/lib/gitlab/serverless/function_uri_spec.rb b/spec/lib/gitlab/serverless/function_uri_spec.rb
new file mode 100644
index 00000000000..cd4abeb89f5
--- /dev/null
+++ b/spec/lib/gitlab/serverless/function_uri_spec.rb
@@ -0,0 +1,81 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Serverless::FunctionURI do
+ let(:function) { 'test-function' }
+ let(:domain) { 'serverless.gitlab.io' }
+ let(:pages_domain) { create(:pages_domain, :instance_serverless, domain: domain) }
+ let!(:cluster) { create(:serverless_domain_cluster, uuid: 'abcdef12345678', pages_domain: pages_domain) }
+ let(:valid_cluster) { 'aba1cdef123456f278' }
+ let(:invalid_cluster) { 'aba1cdef123456f178' }
+ let!(:environment) { create(:environment, name: 'test') }
+
+ let(:valid_uri) { "https://#{function}-#{valid_cluster}#{"%x" % environment.id}-#{environment.slug}.#{domain}" }
+ let(:valid_fqdn) { "#{function}-#{valid_cluster}#{"%x" % environment.id}-#{environment.slug}.#{domain}" }
+ let(:invalid_uri) { "https://#{function}-#{invalid_cluster}#{"%x" % environment.id}-#{environment.slug}.#{domain}" }
+
+ shared_examples 'a valid FunctionURI class' do
+ describe '#to_s' do
+ it 'matches valid URI' do
+ expect(subject.to_s).to eq valid_uri
+ end
+ end
+
+ describe '#function' do
+ it 'returns function' do
+ expect(subject.function).to eq function
+ end
+ end
+
+ describe '#cluster' do
+ it 'returns cluster' do
+ expect(subject.cluster).to eq 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 { described_class.new(function: function, cluster: cluster, environment: environment) }
+
+ it_behaves_like 'a valid FunctionURI class'
+ end
+
+ context 'with invalid arguments' do
+ subject { described_class.new(function: function, environment: environment) }
+
+ it 'raises an exception' do
+ expect { subject }.to raise_error(ArgumentError)
+ end
+ end
+ end
+
+ describe '.parse' do
+ context 'with valid URI' do
+ subject { described_class.parse(valid_uri) }
+
+ it_behaves_like 'a valid FunctionURI class'
+ end
+
+ context 'with valid FQDN' do
+ subject { described_class.parse(valid_fqdn) }
+
+ it_behaves_like 'a valid FunctionURI class'
+ end
+
+ context 'with invalid URI' do
+ subject { described_class.parse(invalid_uri) }
+
+ it 'returns nil' do
+ expect(subject).to be_nil
+ end
+ end
+ end
+end