debian-mirror-gitlab/spec/controllers/projects/clusters/applications_controller_spec.rb

216 lines
6.2 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
describe Projects::Clusters::ApplicationsController do
include AccessMatchersForController
def current_application
Clusters::Cluster::APPLICATIONS[application]
end
2019-07-07 11:18:12 +05:30
shared_examples 'a secure endpoint' do
2020-04-22 19:07:51 +05:30
it 'is allowed for admin when admin mode enabled', :enable_admin_mode do
expect { subject }.to be_allowed_for(:admin)
end
it 'is denied for admin when admin mode disabled' do
expect { subject }.to be_denied_for(:admin)
end
2019-07-07 11:18:12 +05:30
it { expect { subject }.to be_allowed_for(:owner).of(project) }
it { expect { subject }.to be_allowed_for(:maintainer).of(project) }
it { expect { subject }.to be_denied_for(:developer).of(project) }
it { expect { subject }.to be_denied_for(:reporter).of(project) }
it { expect { subject }.to be_denied_for(:guest).of(project) }
it { expect { subject }.to be_denied_for(:user) }
it { expect { subject }.to be_denied_for(:external) }
end
2018-03-17 18:26:18 +05:30
describe 'POST create' do
2019-07-07 11:18:12 +05:30
subject do
post :create, params: params.merge(namespace_id: project.namespace, project_id: project)
end
2018-03-17 18:26:18 +05:30
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
let(:application) { 'helm' }
let(:params) { { application: application, id: cluster.id } }
describe 'functionality' do
let(:user) { create(:user) }
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2018-03-17 18:26:18 +05:30
sign_in(user)
end
it 'schedule an application installation' do
expect(ClusterInstallAppWorker).to receive(:perform_async).with(application, anything).once
2019-07-07 11:18:12 +05:30
expect { subject }.to change { current_application.count }
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:no_content)
2018-03-17 18:26:18 +05:30
expect(cluster.application_helm).to be_scheduled
end
context 'when cluster do not exists' do
before do
cluster.destroy!
end
it 'return 404' do
2019-07-07 11:18:12 +05:30
expect { subject }.not_to change { current_application.count }
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2018-03-17 18:26:18 +05:30
end
end
context 'when application is unknown' do
let(:application) { 'unkwnown-app' }
it 'return 404' do
2020-03-13 15:44:24 +05:30
is_expected.to have_gitlab_http_status(:not_found)
2018-03-17 18:26:18 +05:30
end
end
context 'when application is already installing' do
before do
create(:clusters_applications_helm, :installing, cluster: cluster)
end
it 'returns 400' do
2020-03-13 15:44:24 +05:30
is_expected.to have_gitlab_http_status(:bad_request)
2018-03-17 18:26:18 +05:30
end
end
end
describe 'security' do
before do
allow(ClusterInstallAppWorker).to receive(:perform_async)
end
2019-07-07 11:18:12 +05:30
it_behaves_like 'a secure endpoint'
2019-05-18 00:54:41 +05:30
end
2019-07-07 11:18:12 +05:30
end
2019-05-18 00:54:41 +05:30
2019-07-07 11:18:12 +05:30
describe 'PATCH update' do
subject do
patch :update, params: params.merge(namespace_id: project.namespace, project_id: project)
end
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
let!(:application) { create(:clusters_applications_knative, :installed, cluster: cluster) }
let(:application_name) { application.name }
let(:params) { { application: application_name, id: cluster.id, hostname: "new.example.com" } }
describe 'functionality' do
let(:user) { create(:user) }
before do
project.add_maintainer(user)
sign_in(user)
end
context "when cluster and app exists" do
it "schedules an application update" do
expect(ClusterPatchAppWorker).to receive(:perform_async).with(application.name, anything).once
2020-03-13 15:44:24 +05:30
is_expected.to have_gitlab_http_status(:no_content)
2019-07-07 11:18:12 +05:30
expect(cluster.application_knative).to be_scheduled
end
end
context 'when cluster do not exists' do
before do
cluster.destroy!
end
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:not_found) }
2019-07-07 11:18:12 +05:30
end
context 'when application is unknown' do
let(:application_name) { 'unkwnown-app' }
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:not_found) }
2019-07-07 11:18:12 +05:30
end
context 'when application is already scheduled' do
before do
application.make_scheduled!
end
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:bad_request) }
2019-07-07 11:18:12 +05:30
end
end
describe 'security' do
before do
allow(ClusterPatchAppWorker).to receive(:perform_async)
end
it_behaves_like 'a secure endpoint'
2018-03-17 18:26:18 +05:30
end
end
2019-07-31 22:56:46 +05:30
describe 'DELETE destroy' do
subject do
delete :destroy, params: params.merge(namespace_id: project.namespace, project_id: project)
end
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
let!(:application) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
let(:application_name) { application.name }
let(:params) { { application: application_name, id: cluster.id } }
let(:worker_class) { Clusters::Applications::UninstallWorker }
describe 'functionality' do
let(:user) { create(:user) }
before do
project.add_maintainer(user)
sign_in(user)
end
context "when cluster and app exists" do
it "schedules an application update" do
expect(worker_class).to receive(:perform_async).with(application.name, application.id).once
2020-03-13 15:44:24 +05:30
is_expected.to have_gitlab_http_status(:no_content)
2019-07-31 22:56:46 +05:30
expect(cluster.application_prometheus).to be_scheduled
end
end
context 'when cluster do not exists' do
before do
cluster.destroy!
end
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:not_found) }
2019-07-31 22:56:46 +05:30
end
context 'when application is unknown' do
let(:application_name) { 'unkwnown-app' }
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:not_found) }
2019-07-31 22:56:46 +05:30
end
context 'when application is already scheduled' do
before do
application.make_scheduled!
end
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:bad_request) }
2019-07-31 22:56:46 +05:30
end
end
describe 'security' do
before do
allow(worker_class).to receive(:perform_async)
end
it_behaves_like 'a secure endpoint'
end
end
2018-03-17 18:26:18 +05:30
end