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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-12-23 00:10:39 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-12-23 00:10:39 +0300
commit6c68583a42998b0bb15971785f372197bfc55cd7 (patch)
tree1299dcd6bda4cf7240f85a450fcfddb1f4053320 /spec/finders
parente5f8220301d524167441f8fac5fd5fcf5fc31e1f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders')
-rw-r--r--spec/finders/ci/runner_managers_finder_spec.rb77
-rw-r--r--spec/finders/ci/runners_finder_spec.rb12
2 files changed, 85 insertions, 4 deletions
diff --git a/spec/finders/ci/runner_managers_finder_spec.rb b/spec/finders/ci/runner_managers_finder_spec.rb
new file mode 100644
index 00000000000..c62c05d415e
--- /dev/null
+++ b/spec/finders/ci/runner_managers_finder_spec.rb
@@ -0,0 +1,77 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::RunnerManagersFinder, '#execute', feature_category: :fleet_visibility do
+ subject(:runner_managers) { described_class.new(runner: runner, params: params).execute }
+
+ let_it_be(:runner) { create(:ci_runner) }
+
+ describe 'filter by status' do
+ before_all do
+ freeze_time
+ end
+
+ after :all do
+ unfreeze_time
+ end
+
+ let_it_be(:offline_runner_manager) { create(:ci_runner_machine, runner: runner, contacted_at: 2.hours.ago) }
+ let_it_be(:online_runner_manager) { create(:ci_runner_machine, runner: runner, contacted_at: 1.second.ago) }
+ let_it_be(:never_contacted_runner_manager) { create(:ci_runner_machine, runner: runner, contacted_at: nil) }
+ let_it_be(:stale_runner_manager) do
+ create(
+ :ci_runner_machine,
+ runner: runner,
+ created_at: Ci::RunnerManager.stale_deadline - 1.second,
+ contacted_at: nil
+ )
+ end
+
+ let(:params) { { status: status } }
+
+ context 'for offline' do
+ let(:status) { :offline }
+
+ it { is_expected.to contain_exactly(offline_runner_manager) }
+ end
+
+ context 'for online' do
+ let(:status) { :online }
+
+ it { is_expected.to contain_exactly(online_runner_manager) }
+ end
+
+ context 'for stale' do
+ let(:status) { :stale }
+
+ it { is_expected.to contain_exactly(stale_runner_manager) }
+ end
+
+ context 'for never_contacted' do
+ let(:status) { :never_contacted }
+
+ it { is_expected.to contain_exactly(never_contacted_runner_manager, stale_runner_manager) }
+ end
+
+ context 'for invalid status' do
+ let(:status) { :invalid_status }
+
+ it 'returns all runner managers' do
+ expect(runner_managers).to contain_exactly(
+ offline_runner_manager, online_runner_manager, never_contacted_runner_manager, stale_runner_manager
+ )
+ end
+ end
+ end
+
+ context 'without any filters' do
+ let(:params) { {} }
+
+ let_it_be(:runner_manager) { create(:ci_runner_machine, runner: runner) }
+
+ it 'returns all runner managers' do
+ expect(runner_managers).to contain_exactly(runner_manager)
+ end
+ end
+end
diff --git a/spec/finders/ci/runners_finder_spec.rb b/spec/finders/ci/runners_finder_spec.rb
index fbe44244dba..98e66ca6f31 100644
--- a/spec/finders/ci/runners_finder_spec.rb
+++ b/spec/finders/ci/runners_finder_spec.rb
@@ -112,7 +112,7 @@ RSpec.describe Ci::RunnersFinder, feature_category: :fleet_visibility do
context 'by status' do
Ci::Runner::AVAILABLE_STATUSES.each do |status|
it "calls the corresponding :#{status} scope on Ci::Runner" do
- expect(Ci::Runner).to receive(status.to_sym).and_call_original
+ expect(Ci::Runner).to receive(:with_status).with(status).and_call_original
described_class.new(current_user: admin, params: { status_status: status }).execute
end
@@ -134,10 +134,14 @@ RSpec.describe Ci::RunnersFinder, feature_category: :fleet_visibility do
end
context 'by runner type' do
- it 'calls the corresponding scope on Ci::Runner' do
- expect(Ci::Runner).to receive(:project_type).and_call_original
+ Ci::Runner.runner_types.each_key do |runner_type|
+ context "when runner type is #{runner_type}" do
+ it "calls the corresponding scope on Ci::Runner" do
+ expect(Ci::Runner).to receive(:with_runner_type).with(runner_type).and_call_original
- described_class.new(current_user: admin, params: { type_type: 'project_type' }).execute
+ described_class.new(current_user: admin, params: { type_type: runner_type }).execute
+ end
+ end
end
end