Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/clusters')
-rw-r--r--spec/services/clusters/agents/refresh_authorization_service_spec.rb10
-rw-r--r--spec/services/clusters/cleanup/project_namespace_service_spec.rb13
-rw-r--r--spec/services/clusters/cleanup/service_account_service_spec.rb8
-rw-r--r--spec/services/clusters/integrations/prometheus_health_check_service_spec.rb (renamed from spec/services/clusters/applications/prometheus_health_check_service_spec.rb)32
4 files changed, 47 insertions, 16 deletions
diff --git a/spec/services/clusters/agents/refresh_authorization_service_spec.rb b/spec/services/clusters/agents/refresh_authorization_service_spec.rb
index 77ba81ea9c0..09bec7ae0e8 100644
--- a/spec/services/clusters/agents/refresh_authorization_service_spec.rb
+++ b/spec/services/clusters/agents/refresh_authorization_service_spec.rb
@@ -113,6 +113,16 @@ RSpec.describe Clusters::Agents::RefreshAuthorizationService do
expect(modified_authorization.config).to eq({ 'default_namespace' => 'new-namespace' })
end
+ context 'project does not belong to a group, and is authorizing itself' do
+ let(:root_ancestor) { create(:namespace) }
+ let(:added_project) { project }
+
+ it 'creates an authorization record for the project' do
+ expect(subject).to be_truthy
+ expect(agent.authorized_projects).to contain_exactly(added_project)
+ end
+ end
+
context 'config contains too many projects' do
before do
stub_const("#{described_class}::AUTHORIZED_ENTITY_LIMIT", 1)
diff --git a/spec/services/clusters/cleanup/project_namespace_service_spec.rb b/spec/services/clusters/cleanup/project_namespace_service_spec.rb
index 605aaea17e4..ec510b2e3c5 100644
--- a/spec/services/clusters/cleanup/project_namespace_service_spec.rb
+++ b/spec/services/clusters/cleanup/project_namespace_service_spec.rb
@@ -58,6 +58,19 @@ RSpec.describe Clusters::Cleanup::ProjectNamespaceService do
subject
end
+
+ context 'when cluster.kubeclient is nil' do
+ let(:kubeclient_instance_double) { nil }
+
+ it 'schedules ::ServiceAccountWorker' do
+ expect(Clusters::Cleanup::ServiceAccountWorker).to receive(:perform_async).with(cluster.id)
+ subject
+ end
+
+ it 'deletes namespaces from database' do
+ expect { subject }.to change { cluster.kubernetes_namespaces.exists? }.from(true).to(false)
+ end
+ end
end
context 'when cluster has no namespaces' do
diff --git a/spec/services/clusters/cleanup/service_account_service_spec.rb b/spec/services/clusters/cleanup/service_account_service_spec.rb
index f256df1b2fc..adcdbd84da0 100644
--- a/spec/services/clusters/cleanup/service_account_service_spec.rb
+++ b/spec/services/clusters/cleanup/service_account_service_spec.rb
@@ -44,5 +44,13 @@ RSpec.describe Clusters::Cleanup::ServiceAccountService do
it 'deletes cluster' do
expect { subject }.to change { Clusters::Cluster.where(id: cluster.id).exists? }.from(true).to(false)
end
+
+ context 'when cluster.kubeclient is nil' do
+ let(:kubeclient_instance_double) { nil }
+
+ it 'deletes cluster' do
+ expect { subject }.to change { Clusters::Cluster.where(id: cluster.id).exists? }.from(true).to(false)
+ end
+ end
end
end
diff --git a/spec/services/clusters/applications/prometheus_health_check_service_spec.rb b/spec/services/clusters/integrations/prometheus_health_check_service_spec.rb
index e6c7b147ab7..9db3b9d2417 100644
--- a/spec/services/clusters/applications/prometheus_health_check_service_spec.rb
+++ b/spec/services/clusters/integrations/prometheus_health_check_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute' do
+RSpec.describe Clusters::Integrations::PrometheusHealthCheckService, '#execute' do
let(:service) { described_class.new(cluster) }
subject { service.execute }
@@ -26,10 +26,10 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute'
end
RSpec.shared_examples 'correct health stored' do
- it 'stores the correct health of prometheus app' do
+ it 'stores the correct health of prometheus' do
subject
- expect(prometheus.healthy).to eq(client_healthy)
+ expect(prometheus.healthy?).to eq(client_healthy)
end
end
@@ -43,19 +43,19 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute'
let_it_be(:project) { create(:project) }
let_it_be(:integration) { create(:alert_management_http_integration, project: project) }
- let(:applications_prometheus_healthy) { true }
- let(:prometheus) { create(:clusters_applications_prometheus, status: prometheus_status_value, healthy: applications_prometheus_healthy) }
- let(:cluster) { create(:cluster, :project, application_prometheus: prometheus, projects: [project]) }
+ let(:previous_health_status) { :healthy }
+ let(:prometheus) { create(:clusters_integrations_prometheus, enabled: prometheus_enabled, health_status: previous_health_status) }
+ let(:cluster) { create(:cluster, :project, integration_prometheus: prometheus, projects: [project]) }
- context 'when prometheus not installed' do
- let(:prometheus_status_value) { Clusters::Applications::Prometheus.state_machine.states[:installing].value }
+ context 'when prometheus not enabled' do
+ let(:prometheus_enabled) { false }
it { expect(subject).to eq(nil) }
include_examples 'no alert'
end
- context 'when prometheus installed' do
- let(:prometheus_status_value) { Clusters::Applications::Prometheus.state_machine.states[:installed].value }
+ context 'when prometheus enabled' do
+ let(:prometheus_enabled) { true }
before do
client = instance_double('PrometheusClient', healthy?: client_healthy)
@@ -63,7 +63,7 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute'
end
context 'when newly unhealthy' do
- let(:applications_prometheus_healthy) { true }
+ let(:previous_health_status) { :healthy }
let(:client_healthy) { false }
include_examples 'sends alert'
@@ -71,7 +71,7 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute'
end
context 'when newly healthy' do
- let(:applications_prometheus_healthy) { false }
+ let(:previous_health_status) { :unhealthy }
let(:client_healthy) { true }
include_examples 'no alert'
@@ -79,7 +79,7 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute'
end
context 'when continuously unhealthy' do
- let(:applications_prometheus_healthy) { false }
+ let(:previous_health_status) { :unhealthy }
let(:client_healthy) { false }
include_examples 'no alert'
@@ -87,7 +87,7 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute'
end
context 'when continuously healthy' do
- let(:applications_prometheus_healthy) { true }
+ let(:previous_health_status) { :healthy }
let(:client_healthy) { true }
include_examples 'no alert'
@@ -95,7 +95,7 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute'
end
context 'when first health check and healthy' do
- let(:applications_prometheus_healthy) { nil }
+ let(:previous_health_status) { :unknown }
let(:client_healthy) { true }
include_examples 'no alert'
@@ -103,7 +103,7 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute'
end
context 'when first health check and not healthy' do
- let(:applications_prometheus_healthy) { nil }
+ let(:previous_health_status) { :unknown }
let(:client_healthy) { false }
include_examples 'sends alert'