diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/models/clusters/agent_spec.rb | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/models/clusters/agent_spec.rb')
-rw-r--r-- | spec/models/clusters/agent_spec.rb | 53 |
1 files changed, 34 insertions, 19 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) } |