diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-11 18:08:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-11 18:08:58 +0000 |
commit | 1ca9950d5f890cd8f185e1eda158b969a7244fe2 (patch) | |
tree | 6f62715938a4b2b001705c51c697609a8e0850ae /spec/lib/gitlab/serverless | |
parent | bcc77054ee9aefd1e332e04a4189390fd5a3112e (diff) | |
download | gitlab-ce-1ca9950d5f890cd8f185e1eda158b969a7244fe2.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/serverless')
-rw-r--r-- | spec/lib/gitlab/serverless/service_spec.rb | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/spec/lib/gitlab/serverless/service_spec.rb b/spec/lib/gitlab/serverless/service_spec.rb new file mode 100644 index 00000000000..f618dd02cdb --- /dev/null +++ b/spec/lib/gitlab/serverless/service_spec.rb @@ -0,0 +1,134 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Serverless::Service do + let(:cluster) { create(:cluster) } + let(:environment) { create(:environment) } + let(:attributes) do + { + 'apiVersion' => 'serving.knative.dev/v1alpha1', + 'kind' => 'Service', + 'metadata' => { + 'creationTimestamp' => '2019-10-22T21:19:13Z', + 'name' => 'kubetest', + 'namespace' => 'project1-1-environment1' + }, + 'spec' => { + 'runLatest' => { + 'configuration' => { + 'build' => { + 'template' => { + 'name' => 'some-image' + } + } + } + } + }, + 'environment_scope' => '*', + 'cluster' => cluster, + 'environment' => environment, + 'podcount' => 0 + } + end + + it 'exposes methods extracting data from the attributes hash' do + service = Gitlab::Serverless::Service.new(attributes) + + expect(service.name).to eq('kubetest') + expect(service.namespace).to eq('project1-1-environment1') + expect(service.environment_scope).to eq('*') + expect(service.podcount).to eq(0) + expect(service.created_at).to eq(DateTime.parse('2019-10-22T21:19:13Z')) + expect(service.image).to eq('some-image') + expect(service.cluster).to eq(cluster) + expect(service.environment).to eq(environment) + end + + it 'returns nil for missing attributes' do + service = Gitlab::Serverless::Service.new({}) + + [:name, :namespace, :environment_scope, :cluster, :podcount, :created_at, :image, :description, :url, :environment].each do |method| + expect(service.send(method)).to be_nil + end + end + + describe '#description' do + it 'extracts the description in knative 7 format if available' do + attributes = { + 'spec' => { + 'template' => { + 'metadata' => { + 'annotations' => { + 'Description' => 'some description' + } + } + } + } + } + service = Gitlab::Serverless::Service.new(attributes) + + expect(service.description).to eq('some description') + end + + it 'extracts the description in knative 5/6 format if 7 is not available' do + attributes = { + 'spec' => { + 'runLatest' => { + 'configuration' => { + 'revisionTemplate' => { + 'metadata' => { + 'annotations' => { + 'Description' => 'some description' + } + } + } + } + } + } + } + service = Gitlab::Serverless::Service.new(attributes) + + expect(service.description).to eq('some description') + end + end + + describe '#url' do + it 'returns proxy URL if cluster has serverless domain' do + # cluster = create(:cluster) + knative = create(:clusters_applications_knative, :installed, cluster: cluster) + create(:serverless_domain_cluster, clusters_applications_knative_id: knative.id) + service = Gitlab::Serverless::Service.new(attributes.merge('cluster' => cluster)) + + expect(Gitlab::Serverless::FunctionURI).to receive(:new).with( + function: service.name, + cluster: service.cluster.serverless_domain, + environment: service.environment + ).and_return('https://proxy.example.com') + + expect(service.url).to eq('https://proxy.example.com') + end + + it 'returns the URL from the knative 6/7 format' do + attributes = { + 'status' => { + 'url' => 'https://example.com' + } + } + service = Gitlab::Serverless::Service.new(attributes) + + expect(service.url).to eq('https://example.com') + end + + it 'returns the URL from the knative 5 format' do + attributes = { + 'status' => { + 'domain' => 'example.com' + } + } + service = Gitlab::Serverless::Service.new(attributes) + + expect(service.url).to eq('http://example.com') + end + end +end |