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 | |
parent | bcc77054ee9aefd1e332e04a4189390fd5a3112e (diff) | |
download | gitlab-ce-1ca9950d5f890cd8f185e1eda158b969a7244fe2.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/import_export/project_tree_restorer_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/safe_model_attributes.yml | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/serverless/service_spec.rb | 134 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_spec.rb | 2 |
4 files changed, 138 insertions, 4 deletions
diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index f4d3c9e613e..c899217d164 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -652,10 +652,10 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do setup_import_export_config('light') end - it 'does not import any instance-level services' do + it 'does not import any templated services' do expect(restored_project_json).to eq(true) - expect(project.services.where(instance: true).count).to eq(0) + expect(project.services.where(template: true).count).to eq(0) end it 'imports labels' do diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index 7695617cb57..55e7d6bd1e3 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -453,7 +453,7 @@ Service: - updated_at - active - properties -- instance +- template - push_events - issues_events - commit_events 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 diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 8e9a816ba6a..9a49d334f52 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -18,7 +18,7 @@ describe Gitlab::UsageData do create(:service, project: projects[1], type: 'SlackService', active: true) create(:service, project: projects[2], type: 'SlackService', active: true) create(:service, project: projects[2], type: 'MattermostService', active: false) - create(:service, project: projects[2], type: 'MattermostService', active: true, instance: true) + create(:service, project: projects[2], type: 'MattermostService', active: true, template: true) create(:service, project: projects[2], type: 'CustomIssueTrackerService', active: true) create(:project_error_tracking_setting, project: projects[0]) create(:project_error_tracking_setting, project: projects[1], enabled: false) |