From 56876070aa8784cabf59dd71433458b0ebeb077e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 6 Aug 2019 23:58:17 +0200 Subject: Fix nil take regression --- spec/models/project_spec.rb | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 157103123ad..2e6c81d0a7e 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1156,7 +1156,6 @@ describe Project do describe '#pipeline_for' do let(:project) { create(:project, :repository) } - let!(:pipeline) { create_pipeline(project) } shared_examples 'giving the correct pipeline' do it { is_expected.to eq(pipeline) } @@ -1168,24 +1167,34 @@ describe Project do end end - context 'with explicit sha' do - subject { project.pipeline_for('master', pipeline.sha) } + context 'with a matching pipeline' do + let!(:pipeline) { create_pipeline(project) } + + context 'with explicit sha' do + subject { project.pipeline_for('master', pipeline.sha) } + + it_behaves_like 'giving the correct pipeline' + + context 'with supplied id' do + let!(:other_pipeline) { create_pipeline(project) } - it_behaves_like 'giving the correct pipeline' + subject { project.pipeline_for('master', pipeline.sha, other_pipeline.id) } - context 'with supplied id' do - let!(:other_pipeline) { create_pipeline(project) } + it { is_expected.to eq(other_pipeline) } + end + end - subject { project.pipeline_for('master', pipeline.sha, other_pipeline.id) } + context 'with implicit sha' do + subject { project.pipeline_for('master') } - it { is_expected.to eq(other_pipeline) } + it_behaves_like 'giving the correct pipeline' end end - context 'with implicit sha' do + context 'when there is no matching pipeline' do subject { project.pipeline_for('master') } - it_behaves_like 'giving the correct pipeline' + it { is_expected.to be_nil } end end @@ -1194,11 +1203,9 @@ describe Project do let!(:pipeline) { create_pipeline(project) } let!(:other_pipeline) { create_pipeline(project) } - context 'with implicit sha' do - subject { project.pipelines_for('master') } + subject { project.pipelines_for(project.default_branch, project.commit.sha) } - it { is_expected.to contain_exactly(pipeline, other_pipeline) } - end + it { is_expected.to contain_exactly(pipeline, other_pipeline) } end describe '#builds_enabled' do -- cgit v1.2.1 From 36a01a88ce4c35f3d2b455c7943eeb9649b51163 Mon Sep 17 00:00:00 2001 From: Tiger Watson Date: Wed, 7 Aug 2019 04:40:29 +0000 Subject: Use separate Kubernetes namespaces per environment Kubernetes deployments on new clusters will now have a separate namespace per project environment, instead of sharing a single namespace for the project. Behaviour of existing clusters is unchanged. All new functionality is controlled by the :kubernetes_namespace_per_environment feature flag, which is safe to enable/disable at any time. --- spec/models/project_spec.rb | 48 +++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 30 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 2e6c81d0a7e..dde766c3813 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2594,45 +2594,33 @@ describe Project do end describe '#deployment_variables' do - context 'when project has no deployment service' do - let(:project) { create(:project) } + let(:project) { create(:project) } + let(:environment) { 'production' } - it 'returns an empty array' do - expect(project.deployment_variables).to eq [] - end + subject { project.deployment_variables(environment: environment) } + + before do + expect(project).to receive(:deployment_platform).with(environment: environment) + .and_return(deployment_platform) end - context 'when project uses mock deployment service' do - let(:project) { create(:mock_deployment_project) } + context 'when project has no deployment platform' do + let(:deployment_platform) { nil } - it 'returns an empty array' do - expect(project.deployment_variables).to eq [] - end + it { is_expected.to eq [] } end - context 'when project has a deployment service' do - context 'when user configured kubernetes from CI/CD > Clusters and KubernetesNamespace migration has not been executed' do - let!(:cluster) { create(:cluster, :project, :provided_by_gcp) } - let(:project) { cluster.project } + context 'when project has a deployment platform' do + let(:platform_variables) { %w(platform variables) } + let(:deployment_platform) { double } - it 'does not return variables from this service' do - expect(project.deployment_variables).not_to include( - { key: 'KUBE_TOKEN', value: project.deployment_platform.token, public: false, masked: true } - ) - end + before do + expect(deployment_platform).to receive(:predefined_variables) + .with(project: project, environment_name: environment) + .and_return(platform_variables) end - context 'when user configured kubernetes from CI/CD > Clusters and KubernetesNamespace migration has been executed' do - let!(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, :with_token) } - let!(:cluster) { kubernetes_namespace.cluster } - let(:project) { kubernetes_namespace.project } - - it 'returns token from kubernetes namespace' do - expect(project.deployment_variables).to include( - { key: 'KUBE_TOKEN', value: kubernetes_namespace.service_account_token, public: false, masked: true } - ) - end - end + it { is_expected.to eq platform_variables } end end -- cgit v1.2.1