diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/controllers/groups | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/controllers/groups')
4 files changed, 180 insertions, 4 deletions
diff --git a/spec/controllers/groups/clusters_controller_spec.rb b/spec/controllers/groups/clusters_controller_spec.rb index 6765cf0990a..1593e1290c4 100644 --- a/spec/controllers/groups/clusters_controller_spec.rb +++ b/spec/controllers/groups/clusters_controller_spec.rb @@ -192,6 +192,46 @@ RSpec.describe Groups::ClustersController do end end + it_behaves_like 'GET #metrics_dashboard for dashboard', 'Cluster health' do + let(:cluster) { create(:cluster, :provided_by_gcp, cluster_type: :group_type, groups: [group]) } + + let(:metrics_dashboard_req_params) do + { + id: cluster.id, + group_id: group.name + } + end + end + + describe 'GET #prometheus_proxy' do + let(:proxyable) do + create(:cluster, :provided_by_gcp, cluster_type: :group_type, groups: [group]) + end + + it_behaves_like 'metrics dashboard prometheus api proxy' do + let(:proxyable_params) do + { + id: proxyable.id.to_s, + group_id: group.name + } + end + + context 'with anonymous user' do + let(:prometheus_body) { nil } + + before do + sign_out(user) + end + + it 'returns 404' do + get :prometheus_proxy, params: prometheus_proxy_params + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + end + describe 'POST create for new cluster' do let(:legacy_abac_param) { 'true' } let(:params) do diff --git a/spec/controllers/groups/imports_controller_spec.rb b/spec/controllers/groups/imports_controller_spec.rb index eb43a62b75b..7372c2e9575 100644 --- a/spec/controllers/groups/imports_controller_spec.rb +++ b/spec/controllers/groups/imports_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::ImportsController do +RSpec.describe Groups::ImportsController do describe 'GET #show' do let_it_be(:user) { create(:user) } let_it_be(:group) { create(:group, :private) } diff --git a/spec/controllers/groups/runners_controller_spec.rb b/spec/controllers/groups/runners_controller_spec.rb index 376cd569952..91ff0a53ec7 100644 --- a/spec/controllers/groups/runners_controller_spec.rb +++ b/spec/controllers/groups/runners_controller_spec.rb @@ -6,6 +6,9 @@ RSpec.describe Groups::RunnersController do let(:user) { create(:user) } let(:group) { create(:group) } let(:runner) { create(:ci_runner, :group, groups: [group]) } + let(:project) { create(:project, group: group) } + let(:runner_project) { create(:ci_runner, :project, projects: [project]) } + let(:params_runner_project) { { group_id: group, id: runner_project } } let(:params) { { group_id: group, id: runner } } before do @@ -24,6 +27,13 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:ok) expect(response).to render_template(:show) end + + it 'renders show with 200 status code project runner' do + get :show, params: { group_id: group, id: runner_project } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:show) + end end context 'when user is not owner' do @@ -36,6 +46,12 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:not_found) end + + it 'renders a 404 project runner' do + get :show, params: { group_id: group, id: runner_project } + + expect(response).to have_gitlab_http_status(:not_found) + end end end @@ -51,6 +67,13 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:ok) expect(response).to render_template(:edit) end + + it 'renders show with 200 status code project runner' do + get :edit, params: { group_id: group, id: runner_project } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:edit) + end end context 'when user is not owner' do @@ -63,6 +86,12 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:not_found) end + + it 'renders a 404 project runner' do + get :edit, params: { group_id: group, id: runner_project } + + expect(response).to have_gitlab_http_status(:not_found) + end end end @@ -82,6 +111,17 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:found) expect(runner.reload.description).to eq(new_desc) end + + it 'updates the project runner, ticks the queue, and redirects project runner' do + new_desc = runner_project.description.swapcase + + expect do + post :update, params: params_runner_project.merge(runner: { description: new_desc } ) + end.to change { runner_project.ensure_runner_queue_value } + + expect(response).to have_gitlab_http_status(:found) + expect(runner_project.reload.description).to eq(new_desc) + end end context 'when user is not an owner' do @@ -99,6 +139,17 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:not_found) expect(runner.reload.description).to eq(old_desc) end + + it 'rejects the update and responds 404 project runner' do + old_desc = runner_project.description + + expect do + post :update, params: params_runner_project.merge(runner: { description: old_desc.swapcase } ) + end.not_to change { runner_project.ensure_runner_queue_value } + + expect(response).to have_gitlab_http_status(:not_found) + expect(runner_project.reload.description).to eq(old_desc) + end end end @@ -114,6 +165,31 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:found) expect(Ci::Runner.find_by(id: runner.id)).to be_nil end + + it 'destroys the project runner and redirects' do + delete :destroy, params: params_runner_project + + expect(response).to have_gitlab_http_status(:found) + expect(Ci::Runner.find_by(id: runner_project.id)).to be_nil + end + end + + context 'when user is an owner and runner in multiple projects' do + let(:project_2) { create(:project, group: group) } + let(:runner_project_2) { create(:ci_runner, :project, projects: [project, project_2]) } + let(:params_runner_project_2) { { group_id: group, id: runner_project_2 } } + + before do + group.add_owner(user) + end + + it 'does not destroy the project runner' do + delete :destroy, params: params_runner_project_2 + + expect(response).to have_gitlab_http_status(:found) + expect(flash[:alert]).to eq('Runner was not deleted because it is assigned to multiple projects.') + expect(Ci::Runner.find_by(id: runner_project_2.id)).to be_present + end end context 'when user is not an owner' do @@ -127,6 +203,13 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:not_found) expect(Ci::Runner.find_by(id: runner.id)).to be_present end + + it 'responds 404 and does not destroy the project runner' do + delete :destroy, params: params_runner_project + + expect(response).to have_gitlab_http_status(:not_found) + expect(Ci::Runner.find_by(id: runner_project.id)).to be_present + end end end @@ -146,6 +229,17 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:found) expect(runner.reload.active).to eq(true) end + + it 'marks the project runner as active, ticks the queue, and redirects' do + runner_project.update(active: false) + + expect do + post :resume, params: params_runner_project + end.to change { runner_project.ensure_runner_queue_value } + + expect(response).to have_gitlab_http_status(:found) + expect(runner_project.reload.active).to eq(true) + end end context 'when user is not an owner' do @@ -163,6 +257,17 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:not_found) expect(runner.reload.active).to eq(false) end + + it 'responds 404 and does not activate the project runner' do + runner_project.update(active: false) + + expect do + post :resume, params: params_runner_project + end.not_to change { runner_project.ensure_runner_queue_value } + + expect(response).to have_gitlab_http_status(:not_found) + expect(runner_project.reload.active).to eq(false) + end end end @@ -182,6 +287,17 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:found) expect(runner.reload.active).to eq(false) end + + it 'marks the project runner as inactive, ticks the queue, and redirects' do + runner_project.update(active: true) + + expect do + post :pause, params: params_runner_project + end.to change { runner_project.ensure_runner_queue_value } + + expect(response).to have_gitlab_http_status(:found) + expect(runner_project.reload.active).to eq(false) + end end context 'when user is not an owner' do @@ -199,6 +315,17 @@ RSpec.describe Groups::RunnersController do expect(response).to have_gitlab_http_status(:not_found) expect(runner.reload.active).to eq(true) end + + it 'responds 404 and does not update the project runner or queue' do + runner_project.update(active: true) + + expect do + post :pause, params: params + end.not_to change { runner_project.ensure_runner_queue_value } + + expect(response).to have_gitlab_http_status(:not_found) + expect(runner_project.reload.active).to eq(true) + end end end end diff --git a/spec/controllers/groups/settings/ci_cd_controller_spec.rb b/spec/controllers/groups/settings/ci_cd_controller_spec.rb index 55c19de4aa1..f11bb66caab 100644 --- a/spec/controllers/groups/settings/ci_cd_controller_spec.rb +++ b/spec/controllers/groups/settings/ci_cd_controller_spec.rb @@ -5,8 +5,15 @@ require 'spec_helper' RSpec.describe Groups::Settings::CiCdController do include ExternalAuthorizationServiceHelpers - let(:group) { create(:group) } - let(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:sub_group) { create(:group, parent: group) } + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:project_2) { create(:project, group: sub_group) } + let_it_be(:runner_group) { create(:ci_runner, :group, groups: [group]) } + let_it_be(:runner_project_1) { create(:ci_runner, :project, projects: [project])} + let_it_be(:runner_project_2) { create(:ci_runner, :project, projects: [project_2])} + let_it_be(:runner_project_3) { create(:ci_runner, :project, projects: [project, project_2])} before do sign_in(user) @@ -18,11 +25,12 @@ RSpec.describe Groups::Settings::CiCdController do group.add_owner(user) end - it 'renders show with 200 status code' do + it 'renders show with 200 status code and correct runners' do get :show, params: { group_id: group } expect(response).to have_gitlab_http_status(:ok) expect(response).to render_template(:show) + expect(assigns(:group_runners)).to match_array([runner_group, runner_project_1, runner_project_2, runner_project_3]) end end @@ -35,6 +43,7 @@ RSpec.describe Groups::Settings::CiCdController do get :show, params: { group_id: group } expect(response).to have_gitlab_http_status(:not_found) + expect(assigns(:group_runners)).to be_nil end end |