diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 09:08:43 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 09:08:43 +0000 |
commit | 733befe96ad19f5a02e442c4a9cc8059d3aabbda (patch) | |
tree | dcabd344df040e536a242edc4e3121fb3efca142 /spec | |
parent | 10213bf3b26c3c21f7683471d35d1cd052c41e9c (diff) | |
download | gitlab-ce-733befe96ad19f5a02e442c4a9cc8059d3aabbda.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/deployment_clusters.rb | 9 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/deployment.json | 2 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/deployment_cluster.json (renamed from spec/fixtures/api/schemas/cluster_basic.json) | 6 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/job/job_details.json | 6 | ||||
-rw-r--r-- | spec/frontend/gfm_auto_complete_spec.js | 2 | ||||
-rw-r--r-- | spec/javascripts/badges/dummy_badge.js | 4 | ||||
-rw-r--r-- | spec/javascripts/jobs/components/environments_block_spec.js | 134 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_config/cli_methods_spec.rb | 111 | ||||
-rw-r--r-- | spec/models/deployment_spec.rb | 1 | ||||
-rw-r--r-- | spec/serializers/deployment_cluster_entity_spec.rb (renamed from spec/serializers/cluster_basic_entity_spec.rb) | 14 |
10 files changed, 237 insertions, 52 deletions
diff --git a/spec/factories/deployment_clusters.rb b/spec/factories/deployment_clusters.rb new file mode 100644 index 00000000000..1bdfff79aaf --- /dev/null +++ b/spec/factories/deployment_clusters.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :deployment_cluster, class: 'DeploymentCluster' do + cluster + deployment + kubernetes_namespace { 'the-namespace' } + end +end diff --git a/spec/fixtures/api/schemas/deployment.json b/spec/fixtures/api/schemas/deployment.json index 0cfeadfe548..ac37dd084d3 100644 --- a/spec/fixtures/api/schemas/deployment.json +++ b/spec/fixtures/api/schemas/deployment.json @@ -50,7 +50,7 @@ "cluster": { "oneOf": [ { "type": "null" }, - { "$ref": "cluster_basic.json" } + { "$ref": "deployment_cluster.json" } ] }, "manual_actions": { diff --git a/spec/fixtures/api/schemas/cluster_basic.json b/spec/fixtures/api/schemas/deployment_cluster.json index 6f0e77997f0..86497f98dcb 100644 --- a/spec/fixtures/api/schemas/cluster_basic.json +++ b/spec/fixtures/api/schemas/deployment_cluster.json @@ -10,6 +10,12 @@ { "type": "null" }, { "type": "string" } ] + }, + "kubernetes_namespace": { + "oneOf": [ + { "type": "null" }, + { "type": "string" } + ] } }, "additionalProperties": false diff --git a/spec/fixtures/api/schemas/job/job_details.json b/spec/fixtures/api/schemas/job/job_details.json index cdf7b049ab6..ae05ecea9ef 100644 --- a/spec/fixtures/api/schemas/job/job_details.json +++ b/spec/fixtures/api/schemas/job/job_details.json @@ -15,6 +15,12 @@ "terminal_path": { "type": "string" }, "trigger": { "$ref": "trigger.json" }, "deployment_status": { "$ref": "deployment_status.json" }, + "deployment_cluster": { + "oneOf": [ + { "$ref": "../deployment_cluster.json" }, + { "type": "null" } + ] + }, "runner": { "$ref": "runner.json" }, "runners": { "$ref": "runners.json" }, "has_trace": { "type": "boolean" }, diff --git a/spec/frontend/gfm_auto_complete_spec.js b/spec/frontend/gfm_auto_complete_spec.js index 99869c46f3f..f58615000ee 100644 --- a/spec/frontend/gfm_auto_complete_spec.js +++ b/spec/frontend/gfm_auto_complete_spec.js @@ -4,7 +4,7 @@ import $ from 'jquery'; import GfmAutoComplete, { membersBeforeSave } from 'ee_else_ce/gfm_auto_complete'; import 'jquery.caret'; -import 'at.js'; +import '@gitlab/at.js'; import { TEST_HOST } from 'helpers/test_constants'; import { getJSONFixture } from 'helpers/fixtures'; diff --git a/spec/javascripts/badges/dummy_badge.js b/spec/javascripts/badges/dummy_badge.js index e8a460cdc76..a0dee89736e 100644 --- a/spec/javascripts/badges/dummy_badge.js +++ b/spec/javascripts/badges/dummy_badge.js @@ -1,9 +1,9 @@ -import _ from 'underscore'; +import { uniqueId } from 'lodash'; import { DUMMY_IMAGE_URL, TEST_HOST } from 'spec/test_constants'; import { PROJECT_BADGE } from '~/badges/constants'; export const createDummyBadge = () => { - const id = _.uniqueId(); + const id = uniqueId(); return { id, name: 'TestBadge', diff --git a/spec/javascripts/jobs/components/environments_block_spec.js b/spec/javascripts/jobs/components/environments_block_spec.js index 64a59d659a7..4f2359e83b6 100644 --- a/spec/javascripts/jobs/components/environments_block_spec.js +++ b/spec/javascripts/jobs/components/environments_block_spec.js @@ -4,6 +4,7 @@ import mountComponent from '../../helpers/vue_mount_component_helper'; const TEST_CLUSTER_NAME = 'test_cluster'; const TEST_CLUSTER_PATH = 'path/to/test_cluster'; +const TEST_KUBERNETES_NAMESPACE = 'this-is-a-kubernetes-namespace'; describe('Environments block', () => { const Component = Vue.extend(component); @@ -28,17 +29,18 @@ describe('Environments block', () => { last_deployment: { ...lastDeployment }, }); - const createEnvironmentWithCluster = () => ({ - ...environment, - last_deployment: { - ...lastDeployment, - cluster: { name: TEST_CLUSTER_NAME, path: TEST_CLUSTER_PATH }, - }, + const createDeploymentWithCluster = () => ({ name: TEST_CLUSTER_NAME, path: TEST_CLUSTER_PATH }); + + const createDeploymentWithClusterAndKubernetesNamespace = () => ({ + name: TEST_CLUSTER_NAME, + path: TEST_CLUSTER_PATH, + kubernetes_namespace: TEST_KUBERNETES_NAMESPACE, }); - const createComponent = (deploymentStatus = {}) => { + const createComponent = (deploymentStatus = {}, deploymentCluster = {}) => { vm = mountComponent(Component, { deploymentStatus, + deploymentCluster, iconStatus: status, }); }; @@ -62,15 +64,36 @@ describe('Environments block', () => { expect(findText()).toEqual('This job is deployed to environment.'); }); - it('renders info with cluster', () => { - createComponent({ - status: 'last', - environment: createEnvironmentWithCluster(), + describe('when there is a cluster', () => { + it('renders info with cluster', () => { + createComponent( + { + status: 'last', + environment: createEnvironmentWithLastDeployment(), + }, + createDeploymentWithCluster(), + ); + + expect(findText()).toEqual( + `This job is deployed to environment using cluster ${TEST_CLUSTER_NAME}.`, + ); }); - expect(findText()).toEqual( - `This job is deployed to environment using cluster ${TEST_CLUSTER_NAME}.`, - ); + describe('when there is a kubernetes namespace', () => { + it('renders info with cluster', () => { + createComponent( + { + status: 'last', + environment: createEnvironmentWithLastDeployment(), + }, + createDeploymentWithClusterAndKubernetesNamespace(), + ); + + expect(findText()).toEqual( + `This job is deployed to environment using cluster ${TEST_CLUSTER_NAME} and namespace ${TEST_KUBERNETES_NAMESPACE}.`, + ); + }); + }); }); }); @@ -89,15 +112,36 @@ describe('Environments block', () => { expect(findJobDeploymentLink().getAttribute('href')).toEqual('bar'); }); - it('renders info with cluster', () => { - createComponent({ - status: 'out_of_date', - environment: createEnvironmentWithCluster(), + describe('when there is a cluster', () => { + it('renders info with cluster', () => { + createComponent( + { + status: 'out_of_date', + environment: createEnvironmentWithLastDeployment(), + }, + createDeploymentWithCluster(), + ); + + expect(findText()).toEqual( + `This job is an out-of-date deployment to environment using cluster ${TEST_CLUSTER_NAME}. View the most recent deployment.`, + ); }); - expect(findText()).toEqual( - `This job is an out-of-date deployment to environment using cluster ${TEST_CLUSTER_NAME}. View the most recent deployment.`, - ); + describe('when there is a kubernetes namespace', () => { + it('renders info with cluster', () => { + createComponent( + { + status: 'out_of_date', + environment: createEnvironmentWithLastDeployment(), + }, + createDeploymentWithClusterAndKubernetesNamespace(), + ); + + expect(findText()).toEqual( + `This job is an out-of-date deployment to environment using cluster ${TEST_CLUSTER_NAME} and namespace ${TEST_KUBERNETES_NAMESPACE}. View the most recent deployment.`, + ); + }); + }); }); }); @@ -143,7 +187,7 @@ describe('Environments block', () => { }); describe('without last deployment', () => { - it('renders info about failed deployment', () => { + it('renders info about deployment being created', () => { createComponent({ status: 'creating', environment, @@ -151,6 +195,22 @@ describe('Environments block', () => { expect(findText()).toEqual('This job is creating a deployment to environment.'); }); + + describe('when there is a cluster', () => { + it('inclues information about the cluster', () => { + createComponent( + { + status: 'creating', + environment, + }, + createDeploymentWithCluster(), + ); + + expect(findText()).toEqual( + `This job is creating a deployment to environment using cluster ${TEST_CLUSTER_NAME}.`, + ); + }); + }); }); describe('without environment', () => { @@ -167,10 +227,13 @@ describe('Environments block', () => { describe('with a cluster', () => { it('renders the cluster link', () => { - createComponent({ - status: 'last', - environment: createEnvironmentWithCluster(), - }); + createComponent( + { + status: 'last', + environment: createEnvironmentWithLastDeployment(), + }, + createDeploymentWithCluster(), + ); expect(findText()).toEqual( `This job is deployed to environment using cluster ${TEST_CLUSTER_NAME}.`, @@ -181,18 +244,13 @@ describe('Environments block', () => { describe('when the cluster is missing the path', () => { it('renders the name without a link', () => { - const cluster = { - name: 'the-cluster', - }; - createComponent({ - status: 'last', - environment: Object.assign({}, environment, { - last_deployment: { - ...lastDeployment, - cluster, - }, - }), - }); + createComponent( + { + status: 'last', + environment: createEnvironmentWithLastDeployment(), + }, + { name: 'the-cluster' }, + ); expect(findText()).toContain('using cluster the-cluster.'); diff --git a/spec/lib/gitlab/sidekiq_config/cli_methods_spec.rb b/spec/lib/gitlab/sidekiq_config/cli_methods_spec.rb index 60d946db744..e6d0055df64 100644 --- a/spec/lib/gitlab/sidekiq_config/cli_methods_spec.rb +++ b/spec/lib/gitlab/sidekiq_config/cli_methods_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'fast_spec_helper' +require 'rspec-parameterized' describe Gitlab::SidekiqConfig::CliMethods do let(:dummy_root) { '/tmp/' } @@ -82,7 +83,7 @@ describe Gitlab::SidekiqConfig::CliMethods do end describe '.expand_queues' do - let(:all_queues) do + let(:worker_queues) do ['cronjob:stuck_import_jobs', 'cronjob:stuck_merge_jobs', 'post_receive'] end @@ -92,25 +93,125 @@ describe Gitlab::SidekiqConfig::CliMethods do expect(described_class.expand_queues(['cronjob'])) .to contain_exactly('cronjob') - allow(described_class).to receive(:worker_queues).and_return(all_queues) + allow(described_class).to receive(:worker_queues).and_return(worker_queues) expect(described_class.expand_queues(['cronjob'])) .to contain_exactly('cronjob', 'cronjob:stuck_import_jobs', 'cronjob:stuck_merge_jobs') end it 'expands queue namespaces to concrete queue names' do - expect(described_class.expand_queues(['cronjob'], all_queues)) + expect(described_class.expand_queues(['cronjob'], worker_queues)) .to contain_exactly('cronjob', 'cronjob:stuck_import_jobs', 'cronjob:stuck_merge_jobs') end it 'lets concrete queue names pass through' do - expect(described_class.expand_queues(['post_receive'], all_queues)) + expect(described_class.expand_queues(['post_receive'], worker_queues)) .to contain_exactly('post_receive') end it 'lets unknown queues pass through' do - expect(described_class.expand_queues(['unknown'], all_queues)) + expect(described_class.expand_queues(['unknown'], worker_queues)) .to contain_exactly('unknown') end end + + describe '.query_workers' do + using RSpec::Parameterized::TableSyntax + + let(:queues) do + [ + { + name: 'a', + feature_category: :category_a, + has_external_dependencies: false, + latency_sensitive: false, + resource_boundary: :cpu + }, + { + name: 'a_2', + feature_category: :category_a, + has_external_dependencies: false, + latency_sensitive: true, + resource_boundary: :none + }, + { + name: 'b', + feature_category: :category_b, + has_external_dependencies: true, + latency_sensitive: true, + resource_boundary: :memory + }, + { + name: 'c', + feature_category: :category_c, + has_external_dependencies: false, + latency_sensitive: false, + resource_boundary: :memory + } + ] + end + + context 'with valid input' do + where(:query, :selected_queues) do + # feature_category + 'feature_category=category_a' | %w(a a_2) + 'feature_category=category_a,category_c' | %w(a a_2 c) + 'feature_category=category_a|feature_category=category_c' | %w(a a_2 c) + 'feature_category!=category_a' | %w(b c) + + # has_external_dependencies + 'has_external_dependencies=true' | %w(b) + 'has_external_dependencies=false' | %w(a a_2 c) + 'has_external_dependencies=true,false' | %w(a a_2 b c) + 'has_external_dependencies=true|has_external_dependencies=false' | %w(a a_2 b c) + 'has_external_dependencies!=true' | %w(a a_2 c) + + # latency_sensitive + 'latency_sensitive=true' | %w(a_2 b) + 'latency_sensitive=false' | %w(a c) + 'latency_sensitive=true,false' | %w(a a_2 b c) + 'latency_sensitive=true|latency_sensitive=false' | %w(a a_2 b c) + 'latency_sensitive!=true' | %w(a c) + + # name + 'name=a' | %w(a) + 'name=a,b' | %w(a b) + 'name=a,a_2|name=b' | %w(a a_2 b) + 'name!=a,a_2' | %w(b c) + + # resource_boundary + 'resource_boundary=memory' | %w(b c) + 'resource_boundary=memory,cpu' | %w(a b c) + 'resource_boundary=memory|resource_boundary=cpu' | %w(a b c) + 'resource_boundary!=memory,cpu' | %w(a_2) + + # combinations + 'feature_category=category_a&latency_sensitive=true' | %w(a_2) + 'feature_category=category_a&latency_sensitive=true|feature_category=category_c' | %w(a_2 c) + end + + with_them do + it do + expect(described_class.query_workers(query, queues)) + .to match_array(selected_queues) + end + end + end + + context 'with invalid input' do + where(:query, :error) do + 'feature_category="category_a"' | described_class::InvalidTerm + 'feature_category=' | described_class::InvalidTerm + 'feature_category~category_a' | described_class::InvalidTerm + 'worker_name=a' | described_class::UnknownPredicate + end + + with_them do + it do + expect { described_class.query_workers(query, queues) } + .to raise_error(error) + end + end + end + end end diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index 89fb4eb3ff2..257f699a459 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -18,6 +18,7 @@ describe Deployment do it { is_expected.to delegate_method(:commit).to(:project) } it { is_expected.to delegate_method(:commit_title).to(:commit).as(:try) } it { is_expected.to delegate_method(:manual_actions).to(:deployable).as(:try) } + it { is_expected.to delegate_method(:kubernetes_namespace).to(:deployment_cluster).as(:kubernetes_namespace) } it { is_expected.to validate_presence_of(:ref) } it { is_expected.to validate_presence_of(:sha) } diff --git a/spec/serializers/cluster_basic_entity_spec.rb b/spec/serializers/deployment_cluster_entity_spec.rb index 8c3307a1837..b22a93fcec7 100644 --- a/spec/serializers/cluster_basic_entity_spec.rb +++ b/spec/serializers/deployment_cluster_entity_spec.rb @@ -2,9 +2,9 @@ require 'spec_helper' -describe ClusterBasicEntity do +describe DeploymentClusterEntity do describe '#as_json' do - subject { described_class.new(cluster, request: request).as_json } + subject { described_class.new(deployment, request: request).as_json } let(:maintainer) { create(:user) } let(:developer) { create(:user) } @@ -12,26 +12,30 @@ describe ClusterBasicEntity do let(:request) { double(:request, current_user: current_user) } let(:project) { create(:project) } let(:cluster) { create(:cluster, name: 'the-cluster', projects: [project]) } + let(:deployment) { create(:deployment, cluster: cluster) } + let!(:deployment_cluster) { create(:deployment_cluster, cluster: cluster, deployment: deployment) } before do project.add_maintainer(maintainer) project.add_developer(developer) end - it 'matches cluster_basic entity schema' do - expect(subject.as_json).to match_schema('cluster_basic') + it 'matches deployment_cluster entity schema' do + expect(subject.as_json).to match_schema('deployment_cluster') end it 'exposes the cluster details' do expect(subject[:name]).to eq('the-cluster') expect(subject[:path]).to eq("/#{project.full_path}/-/clusters/#{cluster.id}") + expect(subject[:kubernetes_namespace]).to eq(deployment_cluster.kubernetes_namespace) end context 'when the user does not have permission to view the cluster' do let(:current_user) { developer } - it 'does not include the path' do + it 'does not include the path nor the namespace' do expect(subject[:path]).to be_nil + expect(subject[:kubernetes_namespace]).to be_nil end end end |