summaryrefslogtreecommitdiff
path: root/spec/workers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-19 03:06:07 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-19 03:06:07 +0000
commit7f3bff1556594dcdc1beca40d083ba7263965e21 (patch)
treeab18d957d9bc7b2888c6e9fa9b281a7c1cb8927b /spec/workers
parent8d0aed5e4a6ae59232cfa5ca168fa1b87073520d (diff)
downloadgitlab-ce-7f3bff1556594dcdc1beca40d083ba7263965e21.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/clusters/cleanup/app_worker_spec.rb41
-rw-r--r--spec/workers/clusters/cleanup/project_namespace_worker_spec.rb52
-rw-r--r--spec/workers/clusters/cleanup/service_account_worker_spec.rb27
3 files changed, 120 insertions, 0 deletions
diff --git a/spec/workers/clusters/cleanup/app_worker_spec.rb b/spec/workers/clusters/cleanup/app_worker_spec.rb
new file mode 100644
index 00000000000..29c00db8079
--- /dev/null
+++ b/spec/workers/clusters/cleanup/app_worker_spec.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Clusters::Cleanup::AppWorker do
+ describe '#perform' do
+ subject { worker_instance.perform(cluster.id) }
+
+ let!(:worker_instance) { described_class.new }
+ let!(:cluster) { create(:cluster, :project, :cleanup_uninstalling_applications, provider_type: :gcp) }
+ let!(:logger) { worker_instance.send(:logger) }
+
+ it_behaves_like 'cluster cleanup worker base specs'
+
+ context 'when exceeded the execution limit' do
+ subject { worker_instance.perform(cluster.id, worker_instance.send(:execution_limit)) }
+
+ let(:worker_instance) { described_class.new }
+ let(:logger) { worker_instance.send(:logger) }
+ let!(:helm) { create(:clusters_applications_helm, :installed, cluster: cluster) }
+ let!(:ingress) { create(:clusters_applications_ingress, :scheduled, cluster: cluster) }
+
+ it 'logs the error' do
+ expect(logger).to receive(:error)
+ .with(
+ hash_including(
+ exception: 'ClusterCleanupMethods::ExceededExecutionLimitError',
+ cluster_id: kind_of(Integer),
+ class_name: described_class.name,
+ applications: "helm:installed,ingress:scheduled",
+ cleanup_status: cluster.cleanup_status_name,
+ event: :failed_to_remove_cluster_and_resources,
+ message: "exceeded execution limit of 10 tries"
+ )
+ )
+
+ subject
+ end
+ end
+ end
+end
diff --git a/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb b/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb
new file mode 100644
index 00000000000..8b6f22e9a61
--- /dev/null
+++ b/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Clusters::Cleanup::ProjectNamespaceWorker do
+ describe '#perform' do
+ context 'when cluster.cleanup_status is cleanup_removing_project_namespaces' do
+ let!(:cluster) { create(:cluster, :with_environments, :cleanup_removing_project_namespaces) }
+ let!(:worker_instance) { described_class.new }
+ let!(:logger) { worker_instance.send(:logger) }
+
+ it_behaves_like 'cluster cleanup worker base specs'
+
+ it 'calls Clusters::Cleanup::ProjectNamespaceService' do
+ expect_any_instance_of(Clusters::Cleanup::ProjectNamespaceService).to receive(:execute).once
+
+ subject.perform(cluster.id)
+ end
+
+ context 'when exceeded the execution limit' do
+ subject { worker_instance.perform(cluster.id, worker_instance.send(:execution_limit))}
+
+ it 'logs the error' do
+ expect(logger).to receive(:error)
+ .with(
+ hash_including(
+ exception: 'ClusterCleanupMethods::ExceededExecutionLimitError',
+ cluster_id: kind_of(Integer),
+ class_name: described_class.name,
+ applications: "",
+ cleanup_status: cluster.cleanup_status_name,
+ event: :failed_to_remove_cluster_and_resources,
+ message: "exceeded execution limit of 10 tries"
+ )
+ )
+
+ subject
+ end
+ end
+ end
+
+ context 'when cluster.cleanup_status is not cleanup_removing_project_namespaces' do
+ let!(:cluster) { create(:cluster, :with_environments) }
+
+ it 'does not call Clusters::Cleanup::ProjectNamespaceService' do
+ expect(Clusters::Cleanup::ProjectNamespaceService).not_to receive(:new)
+
+ subject.perform(cluster.id)
+ end
+ end
+ end
+end
diff --git a/spec/workers/clusters/cleanup/service_account_worker_spec.rb b/spec/workers/clusters/cleanup/service_account_worker_spec.rb
new file mode 100644
index 00000000000..9af53dd63c1
--- /dev/null
+++ b/spec/workers/clusters/cleanup/service_account_worker_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Clusters::Cleanup::ServiceAccountWorker do
+ describe '#perform' do
+ let!(:cluster) { create(:cluster, :cleanup_removing_service_account) }
+
+ context 'when cluster.cleanup_status is cleanup_removing_service_account' do
+ it 'calls Clusters::Cleanup::ServiceAccountService' do
+ expect_any_instance_of(Clusters::Cleanup::ServiceAccountService).to receive(:execute).once
+
+ subject.perform(cluster.id)
+ end
+ end
+
+ context 'when cluster.cleanup_status is not cleanup_removing_service_account' do
+ let!(:cluster) { create(:cluster, :with_environments) }
+
+ it 'does not call Clusters::Cleanup::ServiceAccountService' do
+ expect(Clusters::Cleanup::ServiceAccountService).not_to receive(:new)
+
+ subject.perform(cluster.id)
+ end
+ end
+ end
+end