diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-05 21:21:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-05 21:21:08 +0300 |
commit | 534ce3b2d0a6ec24de9c370e5b85c9528ff63e34 (patch) | |
tree | 4ad964818b181fddc0925e33b63f9b1f2ded23d3 /spec/finders/ci/runner_jobs_finder_spec.rb | |
parent | 4ba8ae97071935c39216afc53304c60386bbfa68 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders/ci/runner_jobs_finder_spec.rb')
-rw-r--r-- | spec/finders/ci/runner_jobs_finder_spec.rb | 88 |
1 files changed, 51 insertions, 37 deletions
diff --git a/spec/finders/ci/runner_jobs_finder_spec.rb b/spec/finders/ci/runner_jobs_finder_spec.rb index 755b21ec08f..66cdde756be 100644 --- a/spec/finders/ci/runner_jobs_finder_spec.rb +++ b/spec/finders/ci/runner_jobs_finder_spec.rb @@ -2,26 +2,28 @@ require 'spec_helper' -RSpec.describe Ci::RunnerJobsFinder do - let(:project) { create(:project) } - let(:runner) { create(:ci_runner, :instance) } - let(:user) { create(:user) } +RSpec.describe Ci::RunnerJobsFinder, feature_category: :fleet_visibility do + let_it_be(:project) { create(:project) } + let_it_be(:runner) { create(:ci_runner, :instance) } + let_it_be(:user) { create(:user) } + let_it_be(:runner_manager) { create(:ci_runner_machine, runner: runner) } + let_it_be(:jobs) { create_list(:ci_build, 5, runner_manager: runner_manager, project: project) } + let(:params) { {} } - subject { described_class.new(runner, user, params).execute } + subject(:returned_jobs) { described_class.new(runner, user, params).execute } - before do + before_all do project.add_developer(user) end describe '#execute' do context 'when params is empty' do - let!(:job) { create(:ci_build, runner: runner, project: project) } let!(:job1) { create(:ci_build, project: project) } it 'returns all jobs assigned to Runner' do - is_expected.to match_array(job) - is_expected.not_to match_array(job1) + is_expected.to match_array(jobs) + is_expected.not_to include(job1) end end @@ -36,35 +38,34 @@ RSpec.describe Ci::RunnerJobsFinder do end end - context 'when the user has permission to read all resources' do - let(:user) { create(:user, :admin) } + context 'when the user is admin', :enable_admin_mode do + let_it_be(:user) { create(:user, :admin) } - it 'returns all the jobs assigned to a runner' do - jobs = create_list(:ci_build, 5, runner: runner, project: project) + it { is_expected.to match_array(jobs) } + end - is_expected.to match_array(jobs) + context 'when user is developer' do + before_all do + project.add_developer(user) end + + it { is_expected.to match_array(jobs) } end context 'when the user has different access levels in different projects' do - it 'returns only the jobs the user has permission to see' do - guest_project = create(:project) - reporter_project = create(:project) - - _guest_jobs = create_list(:ci_build, 2, runner: runner, project: guest_project) - reporter_jobs = create_list(:ci_build, 3, runner: runner, project: reporter_project) - - guest_project.add_guest(user) - reporter_project.add_reporter(user) - - is_expected.to match_array(reporter_jobs) + let_it_be(:guest_project) { create(:project).tap { |p| p.add_guest(user) } } + let_it_be(:guest_jobs) { create_list(:ci_build, 2, runner: runner, project: guest_project) } + let_it_be(:reporter_project) { create(:project).tap { |p| p.add_reporter(user) } } + let_it_be(:reporter_jobs) { create_list(:ci_build, 3, runner: runner, project: reporter_project) } + + it 'returns only the jobs the user has permission to see', :aggregate_failures do + is_expected.to include(*reporter_jobs) + is_expected.not_to include(*guest_jobs) end end context 'when the user has reporter access level or greater' do - it 'returns jobs assigned to the Runner that the user has accesss to' do - jobs = create_list(:ci_build, 3, runner: runner, project: project) - + it 'returns jobs assigned to the Runner that the user has access to' do is_expected.to match_array(jobs) end end @@ -73,24 +74,38 @@ RSpec.describe Ci::RunnerJobsFinder do Ci::HasStatus::AVAILABLE_STATUSES.each do |target_status| context "when status is #{target_status}" do let(:params) { { status: target_status } } + let(:exception_status) { (Ci::HasStatus::AVAILABLE_STATUSES - [target_status]).first } let!(:job) { create(:ci_build, runner: runner, project: project, status: target_status) } + let!(:other_job) { create(:ci_build, runner: runner, project: project, status: exception_status) } - before do - exception_status = Ci::HasStatus::AVAILABLE_STATUSES - [target_status] - create(:ci_build, runner: runner, project: project, status: exception_status.first) - end - - it 'returns matched job' do - is_expected.to eq([job]) + it 'returns matched job', :aggregate_failures do + is_expected.to include(job) + is_expected.not_to include(other_job) end end end end + context 'when system_id is specified' do + let_it_be(:runner_manager2) { create(:ci_runner_machine, runner: runner) } + let_it_be(:job2) { create(:ci_build, runner_manager: runner_manager2, project: project) } + + let(:params) { { system_id: runner_manager.system_xid } } + + it 'returns jobs from the specified system' do + expect(returned_jobs).to match_array(jobs) + end + + context 'when specified system_id does not exist' do + let(:params) { { system_id: 'unknown_system' } } + + it { is_expected.to be_empty } + end + end + context 'when order_by and sort are specified' do context 'when order_by id and sort is asc' do let(:params) { { order_by: 'id', sort: 'asc' } } - let!(:jobs) { create_list(:ci_build, 2, runner: runner, project: project, user: create(:user)) } it 'sorts as id: :asc' do is_expected.to eq(jobs.sort_by(&:id)) @@ -101,7 +116,6 @@ RSpec.describe Ci::RunnerJobsFinder do context 'when order_by is specified and sort is not specified' do context 'when order_by id and sort is not specified' do let(:params) { { order_by: 'id' } } - let!(:jobs) { create_list(:ci_build, 2, runner: runner, project: project, user: create(:user)) } it 'sorts as id: :desc' do is_expected.to eq(jobs.sort_by(&:id).reverse) |