diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/services/clusters | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/services/clusters')
-rw-r--r-- | spec/services/clusters/applications/destroy_service_spec.rb | 63 | ||||
-rw-r--r-- | spec/services/clusters/applications/uninstall_service_spec.rb | 77 |
2 files changed, 0 insertions, 140 deletions
diff --git a/spec/services/clusters/applications/destroy_service_spec.rb b/spec/services/clusters/applications/destroy_service_spec.rb deleted file mode 100644 index 7306256e68e..00000000000 --- a/spec/services/clusters/applications/destroy_service_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Clusters::Applications::DestroyService, '#execute' do - let(:cluster) { create(:cluster, :project, :provided_by_gcp) } - let(:user) { create(:user) } - let(:params) { { application: 'prometheus' } } - let(:service) { described_class.new(cluster, user, params) } - let(:test_request) { double } - let(:worker_class) { Clusters::Applications::UninstallWorker } - - subject { service.execute(test_request) } - - before do - allow(worker_class).to receive(:perform_async) - end - - context 'application is not installed' do - it 'raises Clusters::Applications::BaseService::InvalidApplicationError' do - expect(worker_class).not_to receive(:perform_async) - - expect { subject } - .to raise_exception { Clusters::Applications::BaseService::InvalidApplicationError } - .and not_change { Clusters::Applications::Prometheus.count } - .and not_change { Clusters::Applications::Prometheus.with_status(:scheduled).count } - end - end - - context 'application is installed' do - context 'application is schedulable' do - let!(:application) do - create(:clusters_applications_prometheus, :installed, cluster: cluster) - end - - it 'makes application scheduled!' do - subject - - expect(application.reload).to be_scheduled - end - - it 'schedules UninstallWorker' do - expect(worker_class).to receive(:perform_async).with(application.name, application.id) - - subject - end - end - - context 'application is not schedulable' do - let!(:application) do - create(:clusters_applications_prometheus, :updating, cluster: cluster) - end - - it 'raises StateMachines::InvalidTransition' do - expect(worker_class).not_to receive(:perform_async) - - expect { subject } - .to raise_exception { StateMachines::InvalidTransition } - .and not_change { Clusters::Applications::Prometheus.with_status(:scheduled).count } - end - end - end -end diff --git a/spec/services/clusters/applications/uninstall_service_spec.rb b/spec/services/clusters/applications/uninstall_service_spec.rb deleted file mode 100644 index bfe38ba670d..00000000000 --- a/spec/services/clusters/applications/uninstall_service_spec.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Clusters::Applications::UninstallService, '#execute' do - let(:application) { create(:clusters_applications_prometheus, :scheduled) } - let(:service) { described_class.new(application) } - let(:helm_client) { instance_double(Gitlab::Kubernetes::Helm::API) } - let(:worker_class) { Clusters::Applications::WaitForUninstallAppWorker } - - before do - allow(service).to receive(:helm_api).and_return(helm_client) - end - - context 'when there are no errors' do - before do - expect(helm_client).to receive(:uninstall).with(kind_of(Gitlab::Kubernetes::Helm::V3::DeleteCommand)) - allow(worker_class).to receive(:perform_in).and_return(nil) - end - - it 'make the application to be uninstalling' do - expect(application.cluster).not_to be_nil - service.execute - - expect(application).to be_uninstalling - end - - it 'schedule async installation status check' do - expect(worker_class).to receive(:perform_in).once - - service.execute - end - end - - context 'when k8s cluster communication fails' do - let(:error) { Kubeclient::HttpError.new(500, 'system failure', nil) } - - before do - expect(helm_client).to receive(:uninstall).with(kind_of(Gitlab::Kubernetes::Helm::V3::DeleteCommand)).and_raise(error) - end - - include_examples 'logs kubernetes errors' do - let(:error_name) { 'Kubeclient::HttpError' } - let(:error_message) { 'system failure' } - let(:error_code) { 500 } - end - - it 'make the application errored' do - service.execute - - expect(application).to be_uninstall_errored - expect(application.status_reason).to match('Kubernetes error: 500') - end - end - - context 'a non kubernetes error happens' do - let(:application) { create(:clusters_applications_prometheus, :scheduled) } - let(:error) { StandardError.new('something bad happened') } - - before do - expect(helm_client).to receive(:uninstall).with(kind_of(Gitlab::Kubernetes::Helm::V3::DeleteCommand)).and_raise(error) - end - - include_examples 'logs kubernetes errors' do - let(:error_name) { 'StandardError' } - let(:error_message) { 'something bad happened' } - let(:error_code) { nil } - end - - it 'make the application errored' do - service.execute - - expect(application).to be_uninstall_errored - expect(application.status_reason).to eq('Failed to uninstall.') - end - end -end |