2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Clusters::Applications::CreateService do
|
|
|
|
include TestRequestHelpers
|
|
|
|
|
|
|
|
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:params) { { application: 'helm' } }
|
|
|
|
let(:service) { described_class.new(cluster, user, params) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
before do
|
|
|
|
allow(ClusterInstallAppWorker).to receive(:perform_async)
|
2019-03-02 22:35:43 +05:30
|
|
|
allow(ClusterUpgradeAppWorker).to receive(:perform_async)
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
subject { service.execute(test_request) }
|
|
|
|
|
|
|
|
it 'creates an application' do
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
|
|
|
|
cluster.reload
|
|
|
|
end.to change(cluster, :application_helm)
|
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'schedules an install via worker' do
|
|
|
|
expect(ClusterInstallAppWorker).to receive(:perform_async).with('helm', anything).once
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
context 'application already installed' do
|
|
|
|
let!(:application) { create(:clusters_applications_helm, :installed, cluster: cluster) }
|
|
|
|
|
|
|
|
it 'does not create a new application' do
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.not_to change(Clusters::Applications::Helm, :count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'schedules an upgrade for the application' do
|
2019-05-30 16:15:17 +05:30
|
|
|
expect(Clusters::Applications::ScheduleInstallationService).to receive(:new).with(application).and_call_original
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
context 'cert manager application' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
application: 'cert_manager',
|
|
|
|
email: 'test@example.com'
|
|
|
|
}
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
before do
|
|
|
|
allow_any_instance_of(Clusters::Applications::ScheduleInstallationService).to receive(:execute)
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'creates the application' do
|
|
|
|
expect do
|
|
|
|
subject
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
cluster.reload
|
|
|
|
end.to change(cluster, :application_cert_manager)
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'sets the email' do
|
|
|
|
expect(subject.email).to eq('test@example.com')
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
2019-05-30 16:15:17 +05:30
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
context 'jupyter application' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
application: 'jupyter',
|
|
|
|
hostname: 'example.com'
|
|
|
|
}
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
before do
|
|
|
|
allow_any_instance_of(Clusters::Applications::ScheduleInstallationService).to receive(:execute)
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'creates the application' do
|
|
|
|
expect do
|
|
|
|
subject
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
cluster.reload
|
|
|
|
end.to change(cluster, :application_jupyter)
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'sets the hostname' do
|
|
|
|
expect(subject.hostname).to eq('example.com')
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'sets the oauth_application' do
|
|
|
|
expect(subject.oauth_application).to be_present
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
2019-05-30 16:15:17 +05:30
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
context 'knative application' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
application: 'knative',
|
|
|
|
hostname: 'example.com'
|
|
|
|
}
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
before do
|
|
|
|
allow_any_instance_of(Clusters::Applications::ScheduleInstallationService).to receive(:execute)
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'creates the application' do
|
|
|
|
expect do
|
|
|
|
subject
|
2019-05-18 00:54:41 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
cluster.reload
|
|
|
|
end.to change(cluster, :application_knative)
|
|
|
|
end
|
2019-05-18 00:54:41 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'sets the hostname' do
|
|
|
|
expect(subject.hostname).to eq('example.com')
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'invalid application' do
|
|
|
|
let(:params) { { application: 'non-existent' } }
|
|
|
|
|
|
|
|
it 'raises an error' do
|
|
|
|
expect { subject }.to raise_error(Clusters::Applications::CreateService::InvalidApplicationError)
|
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
context 'group cluster' do
|
|
|
|
let(:cluster) { create(:cluster, :provided_by_gcp, :group) }
|
|
|
|
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
before do
|
|
|
|
allow_any_instance_of(Clusters::Applications::ScheduleInstallationService).to receive(:execute)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
where(:application, :association, :allowed) do
|
|
|
|
'helm' | :application_helm | true
|
|
|
|
'ingress' | :application_ingress | true
|
|
|
|
'runner' | :application_runner | false
|
|
|
|
'jupyter' | :application_jupyter | false
|
|
|
|
'prometheus' | :application_prometheus | false
|
|
|
|
end
|
2019-05-18 00:54:41 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
with_them do
|
2019-02-15 15:39:39 +05:30
|
|
|
let(:params) { { application: application } }
|
|
|
|
|
|
|
|
it 'executes for each application' do
|
|
|
|
if allowed
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
|
|
|
|
cluster.reload
|
|
|
|
end.to change(cluster, association)
|
|
|
|
else
|
|
|
|
expect { subject }.to raise_error(Clusters::Applications::CreateService::InvalidApplicationError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
end
|