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/models/clusters')
-rw-r--r--spec/models/clusters/agent_spec.rb53
-rw-r--r--spec/models/clusters/cluster_enabled_grant_spec.rb7
-rw-r--r--spec/models/clusters/cluster_spec.rb4
-rw-r--r--spec/models/clusters/integrations/prometheus_spec.rb38
4 files changed, 77 insertions, 25 deletions
diff --git a/spec/models/clusters/agent_spec.rb b/spec/models/clusters/agent_spec.rb
index f10e0cc8fa7..de67bdb32aa 100644
--- a/spec/models/clusters/agent_spec.rb
+++ b/spec/models/clusters/agent_spec.rb
@@ -7,8 +7,7 @@ RSpec.describe Clusters::Agent do
it { is_expected.to belong_to(:created_by_user).class_name('User').optional }
it { is_expected.to belong_to(:project).class_name('::Project') }
- it { is_expected.to have_many(:agent_tokens).class_name('Clusters::AgentToken') }
- it { is_expected.to have_many(:last_used_agent_tokens).class_name('Clusters::AgentToken') }
+ it { is_expected.to have_many(:agent_tokens).class_name('Clusters::AgentToken').order(Clusters::AgentToken.arel_table[:last_used_at].desc.nulls_last) }
it { is_expected.to have_many(:group_authorizations).class_name('Clusters::Agents::GroupAuthorization') }
it { is_expected.to have_many(:authorized_groups).through(:group_authorizations) }
it { is_expected.to have_many(:project_authorizations).class_name('Clusters::Agents::ProjectAuthorization') }
@@ -41,6 +40,39 @@ RSpec.describe Clusters::Agent do
it { is_expected.to contain_exactly(matching_name) }
end
+
+ describe '.has_vulnerabilities' do
+ let_it_be(:without_vulnerabilities) { create(:cluster_agent, has_vulnerabilities: false) }
+ let_it_be(:with_vulnerabilities) { create(:cluster_agent, has_vulnerabilities: true) }
+
+ context 'when value is not provided' do
+ subject { described_class.has_vulnerabilities }
+
+ it 'returns agents which have vulnerabilities' do
+ is_expected.to contain_exactly(with_vulnerabilities)
+ end
+ end
+
+ context 'when value is provided' do
+ subject { described_class.has_vulnerabilities(value) }
+
+ context 'as true' do
+ let(:value) { true }
+
+ it 'returns agents which have vulnerabilities' do
+ is_expected.to contain_exactly(with_vulnerabilities)
+ end
+ end
+
+ context 'as false' do
+ let(:value) { false }
+
+ it 'returns agents which do not have vulnerabilities' do
+ is_expected.to contain_exactly(without_vulnerabilities)
+ end
+ end
+ end
+ end
end
describe 'validation' do
@@ -117,23 +149,6 @@ RSpec.describe Clusters::Agent do
end
end
- describe '#last_used_agent_tokens' do
- let_it_be(:agent) { create(:cluster_agent) }
-
- subject { agent.last_used_agent_tokens }
-
- context 'agent has no tokens' do
- it { is_expected.to be_empty }
- end
-
- context 'agent has active and inactive tokens' do
- let!(:active_token) { create(:cluster_agent_token, agent: agent, last_used_at: 1.minute.ago) }
- let!(:inactive_token) { create(:cluster_agent_token, agent: agent, last_used_at: 2.hours.ago) }
-
- it { is_expected.to contain_exactly(active_token, inactive_token) }
- end
- end
-
describe '#activity_event_deletion_cutoff' do
let_it_be(:agent) { create(:cluster_agent) }
let_it_be(:event1) { create(:agent_activity_event, agent: agent, recorded_at: 1.hour.ago) }
diff --git a/spec/models/clusters/cluster_enabled_grant_spec.rb b/spec/models/clusters/cluster_enabled_grant_spec.rb
new file mode 100644
index 00000000000..1418d854b41
--- /dev/null
+++ b/spec/models/clusters/cluster_enabled_grant_spec.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Clusters::ClusterEnabledGrant do
+ it { is_expected.to belong_to :namespace }
+end
diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb
index d61bed80aaa..30591a3ff5d 100644
--- a/spec/models/clusters/cluster_spec.rb
+++ b/spec/models/clusters/cluster_spec.rb
@@ -50,6 +50,10 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
it { is_expected.to respond_to :project }
it { is_expected.to be_namespace_per_environment }
+ it_behaves_like 'it has loose foreign keys' do
+ let(:factory_name) { :cluster }
+ end
+
describe 'applications have inverse_of: :cluster option' do
let(:cluster) { create(:cluster) }
let!(:helm) { create(:clusters_applications_helm, cluster: cluster) }
diff --git a/spec/models/clusters/integrations/prometheus_spec.rb b/spec/models/clusters/integrations/prometheus_spec.rb
index e529c751889..d1e40fffee0 100644
--- a/spec/models/clusters/integrations/prometheus_spec.rb
+++ b/spec/models/clusters/integrations/prometheus_spec.rb
@@ -21,11 +21,24 @@ RSpec.describe Clusters::Integrations::Prometheus do
let(:cluster) { create(:cluster, :with_installed_helm) }
it 'deactivates prometheus_integration' do
- expect(Clusters::Applications::DeactivateServiceWorker)
+ expect(Clusters::Applications::DeactivateIntegrationWorker)
.to receive(:perform_async).with(cluster.id, 'prometheus')
integration.destroy!
end
+
+ context 'when the FF :rename_integrations_workers is disabled' do
+ before do
+ stub_feature_flags(rename_integrations_workers: false)
+ end
+
+ it 'uses the old worker' do
+ expect(Clusters::Applications::DeactivateServiceWorker)
+ .to receive(:perform_async).with(cluster.id, 'prometheus')
+
+ integration.destroy!
+ end
+ end
end
describe 'after_save' do
@@ -38,10 +51,10 @@ RSpec.describe Clusters::Integrations::Prometheus do
it 'does not touch project integrations' do
integration # ensure integration exists before we set the expectations
- expect(Clusters::Applications::DeactivateServiceWorker)
+ expect(Clusters::Applications::DeactivateIntegrationWorker)
.not_to receive(:perform_async)
- expect(Clusters::Applications::ActivateServiceWorker)
+ expect(Clusters::Applications::ActivateIntegrationWorker)
.not_to receive(:perform_async)
integration.update!(enabled: enabled)
@@ -51,19 +64,32 @@ RSpec.describe Clusters::Integrations::Prometheus do
context 'when enabling' do
let(:enabled) { false }
- it 'deactivates prometheus_integration' do
- expect(Clusters::Applications::ActivateServiceWorker)
+ it 'activates prometheus_integration' do
+ expect(Clusters::Applications::ActivateIntegrationWorker)
.to receive(:perform_async).with(cluster.id, 'prometheus')
integration.update!(enabled: true)
end
+
+ context 'when the FF :rename_integrations_workers is disabled' do
+ before do
+ stub_feature_flags(rename_integrations_workers: false)
+ end
+
+ it 'uses the old worker' do
+ expect(Clusters::Applications::ActivateServiceWorker)
+ .to receive(:perform_async).with(cluster.id, 'prometheus')
+
+ integration.update!(enabled: true)
+ end
+ end
end
context 'when disabling' do
let(:enabled) { true }
it 'activates prometheus_integration' do
- expect(Clusters::Applications::DeactivateServiceWorker)
+ expect(Clusters::Applications::DeactivateIntegrationWorker)
.to receive(:perform_async).with(cluster.id, 'prometheus')
integration.update!(enabled: false)