diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-11-22 12:31:07 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-11-28 14:47:59 +0300 |
commit | 45f2d0af4173ae8e06b548c4bef1fabe14353c85 (patch) | |
tree | 4036b5f257b0f07a42431a2c2cff41dcbdd28dd1 /spec | |
parent | a8e2094c6591336405a90e4185e89752d38965bf (diff) |
Add test suit for platform::kubernetes
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/branches_controller_spec.rb | 18 | ||||
-rw-r--r-- | spec/features/auto_deploy_spec.rb | 113 | ||||
-rw-r--r-- | spec/features/projects/environments/environment_spec.rb | 51 | ||||
-rw-r--r-- | spec/features/projects/environments/environments_spec.rb | 33 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 23 | ||||
-rw-r--r-- | spec/support/prometheus/additional_metrics_shared_examples.rb | 28 |
7 files changed, 212 insertions, 75 deletions
diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 973d6fed288..019ffc44c07 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -130,6 +130,24 @@ describe Projects::BranchesController do expect(response.location).to include(project_new_blob_path(project, branch)) expect(response).to have_gitlab_http_status(302) end + + it 'redirects to autodeploy setup page' do + result = { status: :success, branch: double(name: branch) } + + 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) + + 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) + end end context 'without issue feature access' do diff --git a/spec/features/auto_deploy_spec.rb b/spec/features/auto_deploy_spec.rb index 4a7c3e4f1ab..327059b86e4 100644 --- a/spec/features/auto_deploy_spec.rb +++ b/spec/features/auto_deploy_spec.rb @@ -4,52 +4,105 @@ describe 'Auto deploy' do let(:user) { create(:user) } let(:project) { create(:project, :repository) } - before do - create :kubernetes_service, project: project - project.team << [user, :master] - sign_in user - end - - context 'when no deployment service is active' do + context 'when user configured kubernetes from Integration > Kubernetes' do before do - project.kubernetes_service.update!(active: false) + create :kubernetes_service, project: project + project.team << [user, :master] + sign_in user + end + + context 'when no deployment service is active' do + before do + project.kubernetes_service.update!(active: false) + end + + it 'does not show a button to set up auto deploy' do + visit project_path(project) + expect(page).to have_no_content('Set up auto deploy') + end end - it 'does not show a button to set up auto deploy' do - visit project_path(project) - expect(page).to have_no_content('Set up auto deploy') + context 'when a deployment service is active' do + before do + project.kubernetes_service.update!(active: true) + visit project_path(project) + end + + it 'shows a button to set up auto deploy' do + expect(page).to have_link('Set up auto deploy') + end + + it 'includes OpenShift as an available template', :js do + click_link 'Set up auto deploy' + click_button 'Apply a GitLab CI Yaml template' + + within '.gitlab-ci-yml-selector' do + expect(page).to have_content('OpenShift') + end + end + + it 'creates a merge request using "auto-deploy" branch', :js do + click_link 'Set up auto deploy' + click_button 'Apply a GitLab CI Yaml template' + within '.gitlab-ci-yml-selector' do + click_on 'OpenShift' + end + wait_for_requests + click_button 'Commit changes' + + expect(page).to have_content('New Merge Request From auto-deploy into master') + end end end - context 'when a deployment service is active' do + context 'when user configured kubernetes from CI/CD > Clusters' do before do - project.kubernetes_service.update!(active: true) - visit project_path(project) + create(:cluster, :provided_by_gcp, projects: [project]) + project.team << [user, :master] + sign_in user end - it 'shows a button to set up auto deploy' do - expect(page).to have_link('Set up auto deploy') + context 'when no deployment service is active' do + before do + project.kubernetes_service.update!(active: false) + end + + it 'does not show a button to set up auto deploy' do + visit project_path(project) + expect(page).to have_no_content('Set up auto deploy') + end end - it 'includes OpenShift as an available template', :js do - click_link 'Set up auto deploy' - click_button 'Apply a GitLab CI Yaml template' + context 'when a deployment service is active' do + before do + project.kubernetes_service.update!(active: true) + visit project_path(project) + end - within '.gitlab-ci-yml-selector' do - expect(page).to have_content('OpenShift') + it 'shows a button to set up auto deploy' do + expect(page).to have_link('Set up auto deploy') end - end - it 'creates a merge request using "auto-deploy" branch', :js do - click_link 'Set up auto deploy' - click_button 'Apply a GitLab CI Yaml template' - within '.gitlab-ci-yml-selector' do - click_on 'OpenShift' + it 'includes OpenShift as an available template', :js do + click_link 'Set up auto deploy' + click_button 'Apply a GitLab CI Yaml template' + + within '.gitlab-ci-yml-selector' do + expect(page).to have_content('OpenShift') + end end - wait_for_requests - click_button 'Commit changes' - expect(page).to have_content('New Merge Request From auto-deploy into master') + it 'creates a merge request using "auto-deploy" branch', :js do + click_link 'Set up auto deploy' + click_button 'Apply a GitLab CI Yaml template' + within '.gitlab-ci-yml-selector' do + click_on 'OpenShift' + end + wait_for_requests + click_button 'Commit changes' + + expect(page).to have_content('New Merge Request From auto-deploy into master') + end end end end diff --git a/spec/features/projects/environments/environment_spec.rb b/spec/features/projects/environments/environment_spec.rb index 5fc3ba54f65..3d64b404a84 100644 --- a/spec/features/projects/environments/environment_spec.rb +++ b/spec/features/projects/environments/environment_spec.rb @@ -101,35 +101,48 @@ feature 'Environment' do end context 'with terminal' do - let(:project) { create(:kubernetes_project, :test_repo) } + shared_examples 'correct behavior with terminal' do + context 'for project master' do + let(:role) { :master } - context 'for project master' do - let(:role) { :master } + scenario 'it shows the terminal button' do + expect(page).to have_terminal_button + end - scenario 'it shows the terminal button' do - expect(page).to have_terminal_button + context 'web terminal', :js do + before do + # Stub #terminals as it causes js-enabled feature specs to render the page incorrectly + allow_any_instance_of(Environment).to receive(:terminals) { nil } + visit terminal_project_environment_path(project, environment) + end + + it 'displays a web terminal' do + expect(page).to have_selector('#terminal') + expect(page).to have_link(nil, href: environment.external_url) + end + end end - context 'web terminal', :js do - before do - # Stub #terminals as it causes js-enabled feature specs to render the page incorrectly - allow_any_instance_of(Environment).to receive(:terminals) { nil } - visit terminal_project_environment_path(project, environment) - end + context 'for developer' do + let(:role) { :developer } - it 'displays a web terminal' do - expect(page).to have_selector('#terminal') - expect(page).to have_link(nil, href: environment.external_url) + scenario 'does not show terminal button' do + expect(page).not_to have_terminal_button end end end - context 'for developer' do - let(:role) { :developer } + context 'when user configured kubernetes from Integration > Kubernetes' do + let(:project) { create(:kubernetes_project, :test_repo) } - scenario 'does not show terminal button' do - expect(page).not_to have_terminal_button - end + it_behaves_like 'correct behavior with terminal' + 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 terminal' end end diff --git a/spec/features/projects/environments/environments_spec.rb b/spec/features/projects/environments/environments_spec.rb index 879ee6f4b9b..1732d7f2a9f 100644 --- a/spec/features/projects/environments/environments_spec.rb +++ b/spec/features/projects/environments/environments_spec.rb @@ -208,22 +208,35 @@ feature 'Environments page', :js do end context 'when kubernetes terminal is available' do - let(:project) { create(:kubernetes_project, :test_repo) } + shared_examples 'correct behavior with terminal' do + context 'for project master' do + let(:role) { :master } - context 'for project master' do - let(:role) { :master } + it 'shows the terminal button' do + expect(page).to have_terminal_button + end + end + + context 'when user is a developer' do + let(:role) { :developer } - it 'shows the terminal button' do - expect(page).to have_terminal_button + it 'does not show terminal button' do + expect(page).not_to have_terminal_button + end end end + + context 'when user configured kubernetes from Integration > Kubernetes' do + let(:project) { create(:kubernetes_project, :test_repo) } - context 'when user is a developer' do - let(:role) { :developer } + it_behaves_like 'correct behavior with terminal' + end - it 'does not show terminal button' do - expect(page).not_to have_terminal_button - 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 terminal' end end end diff --git a/spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb b/spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb index 15eb01eb472..3c143f5305b 100644 --- a/spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb +++ b/spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb @@ -4,11 +4,24 @@ describe Gitlab::Ci::Build::Policy::Kubernetes do let(:pipeline) { create(:ci_pipeline, project: project) } context 'when kubernetes service is active' do - set(:project) { create(:kubernetes_project) } + shared_examples 'correct behavior for satisfied_by?' do + it 'is satisfied by a kubernetes pipeline' do + expect(described_class.new('active')) + .to be_satisfied_by(pipeline) + end + end - it 'is satisfied by a kubernetes pipeline' do - expect(described_class.new('active')) - .to be_satisfied_by(pipeline) + context 'when user configured kubernetes from Integration > Kubernetes' do + let(:project) { create(:kubernetes_project) } + + it_behaves_like 'correct behavior for satisfied_by?' + 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 satisfied_by?' end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 549c97a9afd..78f2a4df36f 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2002,12 +2002,25 @@ describe Project do end context 'when project has a deployment service' do - let(:project) { create(:kubernetes_project) } + shared_examples 'correct behavior with variables' do + it 'returns variables from this service' do + expect(project.deployment_variables).to include( + { key: 'KUBE_TOKEN', value: project.kubernetes_service.token, public: false } + ) + end + end + + context 'when user configured kubernetes from Integration > Kubernetes' do + let(:project) { create(:kubernetes_project) } + + it_behaves_like 'correct behavior with variables' + end + + context 'when user configured kubernetes from CI/CD > Clusters' do + let!(:cluster) { create(:cluster, :project, :provided_by_gcp) } + let(:project) { cluster.project } - it 'returns variables from this service' do - expect(project.deployment_variables).to include( - { key: 'KUBE_TOKEN', value: project.kubernetes_service.token, public: false } - ) + it_behaves_like 'correct behavior with variables' end end end diff --git a/spec/support/prometheus/additional_metrics_shared_examples.rb b/spec/support/prometheus/additional_metrics_shared_examples.rb index 620fa37d455..7e20b4e0232 100644 --- a/spec/support/prometheus/additional_metrics_shared_examples.rb +++ b/spec/support/prometheus/additional_metrics_shared_examples.rb @@ -41,16 +41,30 @@ RSpec.shared_examples 'additional metrics query' do end describe 'project has Kubernetes service' do - let(:project) { create(:kubernetes_project) } - let(:environment) { create(:environment, slug: 'environment-slug', project: project) } - let(:kube_namespace) { project.kubernetes_service.actual_namespace } + shared_examples 'correct behavior with metrics' do + let(:environment) { create(:environment, slug: 'environment-slug', project: project) } + let(:kube_namespace) { project.kubernetes_service.actual_namespace } - it_behaves_like 'query context containing environment slug and filter' + it_behaves_like 'query context containing environment slug and filter' - it 'query context contains kube_namespace' do - expect(subject).to receive(:query_metrics).with(hash_including(kube_namespace: kube_namespace)) + it 'query context contains kube_namespace' do + expect(subject).to receive(:query_metrics).with(hash_including(kube_namespace: kube_namespace)) - subject.query(*query_params) + subject.query(*query_params) + end + end + + context 'when user configured kubernetes from Integration > Kubernetes' do + let(:project) { create(:kubernetes_project) } + + it_behaves_like 'correct behavior with metrics' + 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 metrics' end end |