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/finders/ci/jobs_finder_spec.rb')
-rw-r--r--spec/finders/ci/jobs_finder_spec.rb281
1 files changed, 208 insertions, 73 deletions
diff --git a/spec/finders/ci/jobs_finder_spec.rb b/spec/finders/ci/jobs_finder_spec.rb
index 0b3777a2fe8..57046baafab 100644
--- a/spec/finders/ci/jobs_finder_spec.rb
+++ b/spec/finders/ci/jobs_finder_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Ci::JobsFinder, '#execute' do
+RSpec.describe Ci::JobsFinder, '#execute', feature_category: :continuous_integration do
let_it_be(:user) { create(:user) }
let_it_be(:admin) { create(:user, :admin) }
let_it_be(:project) { create(:project, :private, public_builds: false) }
@@ -13,8 +13,8 @@ RSpec.describe Ci::JobsFinder, '#execute' do
let(:params) { {} }
- context 'no project' do
- subject { described_class.new(current_user: current_user, params: params).execute }
+ context 'when project, pipeline, and runner are blank' do
+ subject(:finder_execute) { described_class.new(current_user: current_user, params: params).execute }
context 'with admin' do
let(:current_user) { admin }
@@ -34,43 +34,139 @@ RSpec.describe Ci::JobsFinder, '#execute' do
end
end
- context 'with normal user' do
- let(:current_user) { user }
+ context 'with admin and admin mode enabled', :enable_admin_mode do
+ let(:current_user) { admin }
- it { is_expected.to be_empty }
- end
+ context 'with param `scope`' do
+ using RSpec::Parameterized::TableSyntax
- context 'without user' do
- let(:current_user) { nil }
+ where(:scope, :expected_jobs) do
+ 'pending' | lazy { [pending_job] }
+ 'running' | lazy { [running_job] }
+ 'finished' | lazy { [successful_job] }
+ %w[running success] | lazy { [running_job, successful_job] }
+ end
- it { is_expected.to be_empty }
- end
+ with_them do
+ let(:params) { { scope: scope } }
- context 'with scope', :enable_admin_mode do
- let(:current_user) { admin }
- let(:jobs) { [pending_job, running_job, successful_job] }
+ it { is_expected.to match_array(expected_jobs) }
+ end
+ end
- using RSpec::Parameterized::TableSyntax
+ context 'with param `runner_type`' do
+ let_it_be(:job_with_group_runner) { create(:ci_build, :success, runner: create(:ci_runner, :group)) }
+ let_it_be(:job_with_instance_runner) { create(:ci_build, :success, runner: create(:ci_runner, :instance)) }
+ let_it_be(:job_with_project_runner) { create(:ci_build, :success, runner: create(:ci_runner, :project)) }
+
+ context 'with feature flag :admin_jobs_filter_runner_type enabled' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:runner_type, :expected_jobs) do
+ 'group_type' | lazy { [job_with_group_runner] }
+ 'instance_type' | lazy { [job_with_instance_runner] }
+ 'project_type' | lazy { [job_with_project_runner] }
+ %w[instance_type project_type] | lazy { [job_with_instance_runner, job_with_project_runner] }
+ end
+
+ with_them do
+ let(:params) { { runner_type: runner_type } }
+ it { is_expected.to match_array(expected_jobs) }
+ end
+ end
- where(:scope, :expected_jobs) do
- 'pending' | lazy { [pending_job] }
- 'running' | lazy { [running_job] }
- 'finished' | lazy { [successful_job] }
- %w[running success] | lazy { [running_job, successful_job] }
+ context 'with feature flag :admin_jobs_filter_runner_type disabled' do
+ let(:params) { { runner_type: 'instance_type' } }
+ let(:expected_jobs) do
+ [
+ job_with_group_runner,
+ job_with_instance_runner,
+ job_with_project_runner,
+ pending_job,
+ running_job,
+ successful_job
+ ]
+ end
+
+ before do
+ stub_feature_flags(admin_jobs_filter_runner_type: false)
+ end
+
+ it { is_expected.to match_array(expected_jobs) }
+ end
end
- with_them do
- let(:params) { { scope: scope } }
+ context "with params" do
+ let_it_be(:job_with_running_status_and_group_runner) do
+ create(:ci_build, :running, runner: create(:ci_runner, :group))
+ end
+
+ let_it_be(:job_with_instance_runner) { create(:ci_build, :success, runner: create(:ci_runner, :instance)) }
+ let_it_be(:job_with_project_runner) { create(:ci_build, :success, runner: create(:ci_runner, :project)) }
+
+ context 'with feature flag :admin_jobs_filter_runner_type enabled' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:param_runner_type, :param_scope, :expected_jobs) do
+ 'group_type' | 'running' | lazy { [job_with_running_status_and_group_runner] }
+ %w[instance_type project_type] | 'finished' | lazy { [job_with_instance_runner, job_with_project_runner] }
+ %w[instance_type project_type] | 'pending' | lazy { [] }
+ end
+
+ with_them do
+ let(:params) { { runner_type: param_runner_type, scope: param_scope } }
+
+ it { is_expected.to match_array(expected_jobs) }
+ end
+ end
- it { is_expected.to match_array(expected_jobs) }
+ context 'with feature flag :admin_jobs_filter_runner_type disabled' do
+ before do
+ stub_feature_flags(admin_jobs_filter_runner_type: false)
+ end
+
+ using RSpec::Parameterized::TableSyntax
+
+ where(:param_runner_type, :param_scope, :expected_jobs) do
+ 'group_type' | 'running' | lazy do
+ [job_with_running_status_and_group_runner, running_job]
+ end
+ %w[instance_type project_type] | 'finished' | lazy do
+ [
+ job_with_instance_runner,
+ job_with_project_runner,
+ successful_job
+ ]
+ end
+ %w[instance_type project_type] | 'pending' | lazy { [pending_job] }
+ end
+
+ with_them do
+ let(:params) { { runner_type: param_runner_type, scope: param_scope } }
+
+ it { is_expected.to match_array(expected_jobs) }
+ end
+ end
end
end
+
+ context 'with user not being project member' do
+ let(:current_user) { user }
+
+ it { is_expected.to be_empty }
+ end
+
+ context 'without user' do
+ let(:current_user) { nil }
+
+ it { is_expected.to be_empty }
+ end
end
- context 'a project is present' do
+ context 'when project is present' do
subject { described_class.new(current_user: user, project: project, params: params).execute }
- context 'user has access to the project' do
+ context 'with user being project maintainer' do
before do
project.add_maintainer(user)
end
@@ -78,9 +174,47 @@ RSpec.describe Ci::JobsFinder, '#execute' do
it 'returns jobs for the specified project' do
expect(subject).to match_array([successful_job])
end
+
+ context 'when artifacts are present for some jobs' do
+ let_it_be(:job_with_artifacts) { create(:ci_build, :success, pipeline: pipeline, name: 'test') }
+ let_it_be(:artifact) { create(:ci_job_artifact, job: job_with_artifacts) }
+
+ context 'when with_artifacts is true' do
+ let(:params) { { with_artifacts: true } }
+
+ it 'returns only jobs with artifacts' do
+ expect(subject).to match_array([job_with_artifacts])
+ end
+ end
+
+ context 'when with_artifacts is false' do
+ let(:params) { { with_artifacts: false } }
+
+ it 'returns all jobs' do
+ expect(subject).to match_array([successful_job, job_with_artifacts])
+ end
+ end
+
+ context "with param `scope" do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:param_scope, :expected_jobs) do
+ 'success' | lazy { [successful_job, job_with_artifacts] }
+ '[success pending]' | lazy { [successful_job, job_with_artifacts] }
+ 'pending' | lazy { [] }
+ nil | lazy { [successful_job, job_with_artifacts] }
+ end
+
+ with_them do
+ let(:params) { { with_artifacts: false, scope: param_scope } }
+
+ it { is_expected.to match_array(expected_jobs) }
+ end
+ end
+ end
end
- context 'user has no access to project builds' do
+ context 'with user being project guest' do
before do
project.add_guest(user)
end
@@ -99,79 +233,80 @@ RSpec.describe Ci::JobsFinder, '#execute' do
end
end
- context 'when artifacts are present for some jobs' do
- let_it_be(:job_with_artifacts) { create(:ci_build, :success, pipeline: pipeline, name: 'test') }
- let_it_be(:artifact) { create(:ci_job_artifact, job: job_with_artifacts) }
-
- subject { described_class.new(current_user: user, project: project, params: params).execute }
-
- before do
- project.add_maintainer(user)
- end
-
- context 'when with_artifacts is true' do
- let(:params) { { with_artifacts: true } }
+ context 'when pipeline is present' do
+ subject { described_class.new(current_user: user, pipeline: pipeline, params: params).execute }
- it 'returns only jobs with artifacts' do
- expect(subject).to match_array([job_with_artifacts])
+ context 'with user being project maintainer' do
+ before_all do
+ project.add_maintainer(user)
+ successful_job.update!(retried: true)
end
- end
- context 'when with_artifacts is false' do
- let(:params) { { with_artifacts: false } }
+ let_it_be(:job_4) { create(:ci_build, :success, pipeline: pipeline, name: 'build') }
- it 'returns all jobs' do
- expect(subject).to match_array([successful_job, job_with_artifacts])
+ it 'does not return retried jobs by default' do
+ expect(subject).to match_array([job_4])
end
- end
- end
-
- context 'when pipeline is present' do
- before_all do
- project.add_maintainer(user)
- successful_job.update!(retried: true)
- end
-
- let_it_be(:job_4) { create(:ci_build, :success, pipeline: pipeline, name: 'build') }
- subject { described_class.new(current_user: user, pipeline: pipeline, params: params).execute }
+ context 'when include_retried is false' do
+ let(:params) { { include_retried: false } }
- it 'does not return retried jobs by default' do
- expect(subject).to match_array([job_4])
- end
+ it 'does not return retried jobs' do
+ expect(subject).to match_array([job_4])
+ end
+ end
- context 'when include_retried is false' do
- let(:params) { { include_retried: false } }
+ context 'when include_retried is true' do
+ let(:params) { { include_retried: true } }
- it 'does not return retried jobs' do
- expect(subject).to match_array([job_4])
+ it 'returns retried jobs' do
+ expect(subject).to match_array([successful_job, job_4])
+ end
end
end
- context 'when include_retried is true' do
- let(:params) { { include_retried: true } }
+ context 'without user' do
+ let(:user) { nil }
- it 'returns retried jobs' do
- expect(subject).to match_array([successful_job, job_4])
+ it 'returns no jobs' do
+ expect(subject).to be_empty
end
end
end
- context 'a runner is present' do
+ context 'when runner is present' do
let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) }
let_it_be(:job_4) { create(:ci_build, :success, runner: runner) }
- subject { described_class.new(current_user: user, runner: runner, params: params).execute }
+ subject(:execute) { described_class.new(current_user: user, runner: runner, params: params).execute }
- context 'user has access to the runner', :enable_admin_mode do
+ context 'when current user is an admin' do
let(:user) { admin }
- it 'returns jobs for the specified project' do
- expect(subject).to match_array([job_4])
+ context 'when admin mode is enabled', :enable_admin_mode do
+ it 'returns jobs for the specified project' do
+ expect(subject).to contain_exactly job_4
+ end
+
+ context 'with params' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:param_runner_type, :param_scope, :expected_jobs) do
+ 'project_type' | 'success' | lazy { [job_4] }
+ 'instance_type' | nil | lazy { [] }
+ nil | 'pending' | lazy { [] }
+ end
+
+ with_them do
+ let(:params) { { runner_type: param_runner_type, scope: param_scope } }
+
+ it { is_expected.to match_array(expected_jobs) }
+ end
+ end
end
end
- context 'user has no access to project builds' do
+ context 'with user being project guest' do
let_it_be(:guest) { create(:user) }
let(:user) { guest }