diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-11-27 21:48:54 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-11-28 20:47:59 +0900 |
commit | 1d7e3ef1a55991e057213add556926eb13e0bd48 (patch) | |
tree | 42a63fbc0cb956d2207340aa86ba57dd1e39d572 | |
parent | 5324383dba07d60407a5b947f27695867ad45843 (diff) | |
download | gitlab-ce-1d7e3ef1a55991e057213add556926eb13e0bd48.tar.gz |
Duplicate spec for Platform::Kubernetes with kubernetes_project
-rw-r--r-- | spec/controllers/projects/branches_controller_spec.rb | 52 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 28 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 19 | ||||
-rw-r--r-- | spec/models/environment_spec.rb | 25 | ||||
-rw-r--r-- | spec/workers/reactive_caching_worker_spec.rb | 22 |
5 files changed, 102 insertions, 44 deletions
diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 019ffc44c07..83974b2c876 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -113,40 +113,44 @@ describe Projects::BranchesController do expect(response).to redirect_to project_tree_path(project, branch) end - it 'redirects to autodeploy setup page' do - result = { status: :success, branch: double(name: branch) } + context 'when user configured kubernetes from Integration > Kubernetes' do + it 'redirects to autodeploy setup page' do + result = { status: :success, branch: double(name: branch) } - project.services << build(:kubernetes_service) + project.services << build(:kubernetes_service) - expect_any_instance_of(CreateBranchService).to receive(:execute).and_return(result) - expect(SystemNoteService).to receive(:new_issue_branch).and_return(true) + expect_any_instance_of(CreateBranchService).to receive(:execute).and_return(result) + expect(SystemNoteService).to receive(:new_issue_branch).and_return(true) - post :create, - namespace_id: project.namespace.to_param, - project_id: project.to_param, - branch_name: branch, - issue_iid: issue.iid + post :create, + namespace_id: project.namespace.to_param, + project_id: project.to_param, + branch_name: branch, + issue_iid: issue.iid - expect(response.location).to include(project_new_blob_path(project, branch)) - expect(response).to have_gitlab_http_status(302) + expect(response.location).to include(project_new_blob_path(project, branch)) + expect(response).to have_gitlab_http_status(302) + end end - it 'redirects to autodeploy setup page' do - result = { status: :success, branch: double(name: branch) } + context 'when user configured kubernetes from CI/CD > Clusters' do + it 'redirects to autodeploy setup page' do + result = { status: :success, branch: double(name: branch) } - create(:cluster, :provided_by_gcp, projects: [project]) + create(:cluster, :provided_by_gcp, projects: [project]) - expect_any_instance_of(CreateBranchService).to receive(:execute).and_return(result) - expect(SystemNoteService).to receive(:new_issue_branch).and_return(true) + expect_any_instance_of(CreateBranchService).to receive(:execute).and_return(result) + expect(SystemNoteService).to receive(:new_issue_branch).and_return(true) - post :create, - namespace_id: project.namespace.to_param, - project_id: project.to_param, - branch_name: branch, - issue_iid: issue.iid + post :create, + namespace_id: project.namespace.to_param, + project_id: project.to_param, + branch_name: branch, + issue_iid: issue.iid - expect(response.location).to include(project_new_blob_path(project, branch)) - expect(response).to have_gitlab_http_status(302) + expect(response.location).to include(project_new_blob_path(project, branch)) + expect(response).to have_gitlab_http_status(302) + end end end diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index d72f8553f55..4f44f35205e 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -178,15 +178,29 @@ module Gitlab end context 'when kubernetes is active' do - let(:project) { create(:kubernetes_project) } - let(:pipeline) { create(:ci_empty_pipeline, project: project) } + shared_examples 'correct behavior for kubernetes policy' do + it 'returns seeds for kubernetes dependent job' do + seeds = subject.stage_seeds(pipeline) - it 'returns seeds for kubernetes dependent job' do - seeds = subject.stage_seeds(pipeline) + expect(seeds.size).to eq 2 + expect(seeds.first.builds.dig(0, :name)).to eq 'spinach' + expect(seeds.second.builds.dig(0, :name)).to eq 'production' + end + end - expect(seeds.size).to eq 2 - expect(seeds.first.builds.dig(0, :name)).to eq 'spinach' - expect(seeds.second.builds.dig(0, :name)).to eq 'production' + context 'when user configured kubernetes from Integration > Kubernetes' do + let(:project) { create(:kubernetes_project) } + let(:pipeline) { create(:ci_empty_pipeline, project: project) } + + it_behaves_like 'correct behavior for kubernetes policy' + end + + context 'when user configured kubernetes from CI/CD > Clusters' do + let!(:cluster) { create(:cluster, :project, :provided_by_gcp) } + let(:project) { cluster.project } + let(:pipeline) { create(:ci_empty_pipeline, project: project) } + + it_behaves_like 'correct behavior for kubernetes policy' end end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 3a19a0753e2..c53942ed61c 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -557,10 +557,23 @@ describe Ci::Pipeline, :mailer do describe '#has_kubernetes_active?' do context 'when kubernetes is active' do - let(:project) { create(:kubernetes_project) } + shared_examples 'correct behavior with has_kubernetes_active?' do + it 'returns true' do + expect(pipeline).to have_kubernetes_active + end + end - it 'returns true' do - expect(pipeline).to have_kubernetes_active + context 'when user configured kubernetes from Integration > Kubernetes' do + let(:project) { create(:kubernetes_project) } + + it_behaves_like 'correct behavior with has_kubernetes_active?' + end + + context 'when user configured kubernetes from CI/CD > Clusters' do + let!(:cluster) { create(:cluster, :project, :provided_by_gcp) } + let(:project) { cluster.project } + + it_behaves_like 'correct behavior with has_kubernetes_active?' end end diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 1ce1d595c60..de030844a28 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -327,15 +327,28 @@ describe Environment do context 'when the enviroment is available' do context 'with a deployment service' do - let(:project) { create(:kubernetes_project) } + shared_examples 'correct behavior for has_terminals?' do + context 'and a deployment' do + let!(:deployment) { create(:deployment, environment: environment) } + it { is_expected.to be_truthy } + end - context 'and a deployment' do - let!(:deployment) { create(:deployment, environment: environment) } - it { is_expected.to be_truthy } + context 'but no deployments' do + it { is_expected.to be_falsy } + end end - context 'but no deployments' do - it { is_expected.to be_falsy } + context 'when user configured kubernetes from Integration > Kubernetes' do + let(:project) { create(:kubernetes_project) } + + it_behaves_like 'correct behavior for has_terminals?' + end + + context 'when user configured kubernetes from CI/CD > Clusters' do + let!(:cluster) { create(:cluster, :project, :provided_by_gcp) } + let(:project) { cluster.project } + + it_behaves_like 'correct behavior for has_terminals?' end end diff --git a/spec/workers/reactive_caching_worker_spec.rb b/spec/workers/reactive_caching_worker_spec.rb index 5f4453c15d6..98282af2d18 100644 --- a/spec/workers/reactive_caching_worker_spec.rb +++ b/spec/workers/reactive_caching_worker_spec.rb @@ -1,15 +1,29 @@ require 'spec_helper' describe ReactiveCachingWorker do - let(:project) { create(:kubernetes_project) } let(:service) { project.deployment_service } subject { described_class.new.perform("KubernetesService", service.id) } describe '#perform' do - it 'calls #exclusively_update_reactive_cache!' do - expect_any_instance_of(KubernetesService).to receive(:exclusively_update_reactive_cache!) + shared_examples 'correct behavior with perform' do + it 'calls #exclusively_update_reactive_cache!' do + expect_any_instance_of(KubernetesService).to receive(:exclusively_update_reactive_cache!) - subject + subject + end + end + + context 'when user configured kubernetes from Integration > Kubernetes' do + let(:project) { create(:kubernetes_project) } + + it_behaves_like 'correct behavior with perform' + end + + context 'when user configured kubernetes from CI/CD > Clusters' do + let!(:cluster) { create(:cluster, :project, :provided_by_gcp) } + let(:project) { cluster.project } + + it_behaves_like 'correct behavior with perform' end end end |