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>2020-11-19 11:27:35 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 11:27:35 +0300
commit7e9c479f7de77702622631cff2628a9c8dcbc627 (patch)
treec8f718a08e110ad7e1894510980d2155a6549197 /spec/finders/ci
parente852b0ae16db4052c1c567d9efa4facc81146e88 (diff)
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/finders/ci')
-rw-r--r--spec/finders/ci/commit_statuses_finder_spec.rb178
-rw-r--r--spec/finders/ci/jobs_finder_spec.rb141
2 files changed, 212 insertions, 107 deletions
diff --git a/spec/finders/ci/commit_statuses_finder_spec.rb b/spec/finders/ci/commit_statuses_finder_spec.rb
new file mode 100644
index 00000000000..1aa9cb12432
--- /dev/null
+++ b/spec/finders/ci/commit_statuses_finder_spec.rb
@@ -0,0 +1,178 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::CommitStatusesFinder, '#execute' do
+ let_it_be(:project) { create(:project, :public, :repository) }
+ let_it_be(:release) { create(:release, project: project) }
+ let_it_be(:user) { create(:user) }
+
+ context 'tag refs' do
+ let_it_be(:tags) { TagsFinder.new(project.repository, {}).execute }
+ let(:subject) { described_class.new(project, project.repository, user, tags).execute }
+
+ context 'no pipelines' do
+ it 'returns nil' do
+ expect(subject).to be_blank
+ end
+ end
+
+ context 'when multiple tags exist' do
+ before do
+ create(:ci_pipeline,
+ project: project,
+ ref: 'v1.1.0',
+ sha: project.commit('v1.1.0').sha,
+ status: :running)
+ create(:ci_pipeline,
+ project: project,
+ ref: 'v1.0.0',
+ sha: project.commit('v1.0.0').sha,
+ status: :success)
+ end
+
+ it 'all relevant commit statuses are received' do
+ expect(subject['v1.1.0'].group).to eq("running")
+ expect(subject['v1.0.0'].group).to eq("success")
+ end
+ end
+
+ context 'when a tag has multiple pipelines' do
+ before do
+ create(:ci_pipeline,
+ project: project,
+ ref: 'v1.0.0',
+ sha: project.commit('v1.0.0').sha,
+ status: :running,
+ created_at: 6.months.ago)
+ create(:ci_pipeline,
+ project: project,
+ ref: 'v1.0.0',
+ sha: project.commit('v1.0.0').sha,
+ status: :success,
+ created_at: 2.months.ago)
+ end
+
+ it 'chooses the latest to determine status' do
+ expect(subject['v1.0.0'].group).to eq("success")
+ end
+ end
+ end
+
+ context 'branch refs' do
+ let(:subject) { described_class.new(project, project.repository, user, branches).execute }
+
+ before do
+ project.add_developer(user)
+ end
+
+ context 'no pipelines' do
+ let(:branches) { BranchesFinder.new(project.repository, {}).execute }
+
+ it 'returns nil' do
+ expect(subject).to be_blank
+ end
+ end
+
+ context 'when a branch has multiple pipelines' do
+ let(:branches) { BranchesFinder.new(project.repository, {}).execute }
+
+ before do
+ sha = project.repository.create_file(user, generate(:branch), 'content', message: 'message', branch_name: 'master')
+ create(:ci_pipeline,
+ project: project,
+ user: user,
+ ref: "master",
+ sha: sha,
+ status: :running,
+ created_at: 6.months.ago)
+ create(:ci_pipeline,
+ project: project,
+ user: user,
+ ref: "master",
+ sha: sha,
+ status: :success,
+ created_at: 2.months.ago)
+ end
+
+ it 'chooses the latest to determine status' do
+ expect(subject["master"].group).to eq("success")
+ end
+ end
+
+ context 'when multiple branches exist' do
+ let(:branches) { BranchesFinder.new(project.repository, {}).execute }
+
+ before do
+ master_sha = project.repository.create_file(user, generate(:branch), 'content', message: 'message', branch_name: 'master')
+ create(:ci_pipeline,
+ project: project,
+ user: user,
+ ref: "master",
+ sha: master_sha,
+ status: :running,
+ created_at: 6.months.ago)
+ test_sha = project.repository.create_file(user, generate(:branch), 'content', message: 'message', branch_name: 'test')
+ create(:ci_pipeline,
+ project: project,
+ user: user,
+ ref: "test",
+ sha: test_sha,
+ status: :success,
+ created_at: 2.months.ago)
+ end
+
+ it 'all relevant commit statuses are received' do
+ expect(subject["master"].group).to eq("running")
+ expect(subject["test"].group).to eq("success")
+ end
+ end
+ end
+
+ context 'CI pipelines visible to' do
+ let_it_be(:tags) { TagsFinder.new(project.repository, {}).execute }
+ let(:subject) { described_class.new(project, project.repository, user, tags).execute }
+
+ before do
+ create(:ci_pipeline,
+ project: project,
+ ref: 'v1.1.0',
+ sha: project.commit('v1.1.0').sha,
+ status: :running)
+ end
+
+ context 'everyone' do
+ it 'returns something' do
+ expect(subject).not_to be_blank
+ end
+ end
+
+ context 'project members only' do
+ before do
+ project.project_feature.update!(builds_access_level: ProjectFeature::PRIVATE)
+ end
+
+ it 'returns nil' do
+ expect(subject).to be_empty
+ end
+ end
+
+ context 'when not a member of a private project' do
+ let(:private_project) { create(:project, :private, :repository) }
+ let(:private_tags) { TagsFinder.new(private_tags.repository, {}).execute }
+ let(:private_subject) { described_class.new(private_project, private_project.repository, user, tags).execute }
+
+ before do
+ create(:ci_pipeline,
+ project: private_project,
+ ref: 'v1.1.0',
+ sha: private_project.commit('v1.1.0').sha,
+ status: :running)
+ end
+
+ it 'returns nil' do
+ expect(private_subject).to be_empty
+ end
+ end
+ end
+end
diff --git a/spec/finders/ci/jobs_finder_spec.rb b/spec/finders/ci/jobs_finder_spec.rb
index a6a41c36489..4a6585e3f2b 100644
--- a/spec/finders/ci/jobs_finder_spec.rb
+++ b/spec/finders/ci/jobs_finder_spec.rb
@@ -36,135 +36,62 @@ RSpec.describe Ci::JobsFinder, '#execute' do
end
end
- context 'with ci_jobs_finder_refactor ff enabled' do
- before do
- stub_feature_flags(ci_jobs_finder_refactor: true)
- end
-
- context 'scope is present' do
- let(:jobs) { [job_1, job_2, job_3] }
-
- where(:scope, :index) do
- [
- ['pending', 0],
- ['running', 1],
- ['finished', 2]
- ]
- end
-
- with_them do
- let(:params) { { scope: scope } }
-
- it { expect(subject).to match_array([jobs[index]]) }
- end
+ context 'scope is present' do
+ let(:jobs) { [job_1, job_2, job_3] }
+
+ where(:scope, :index) do
+ [
+ ['pending', 0],
+ ['running', 1],
+ ['finished', 2]
+ ]
end
- context 'scope is an array' do
- let(:jobs) { [job_1, job_2, job_3] }
- let(:params) {{ scope: ['running'] }}
+ with_them do
+ let(:params) { { scope: scope } }
- it 'filters by the job statuses in the scope' do
- expect(subject).to match_array([job_2])
- end
+ it { expect(subject).to match_array([jobs[index]]) }
end
end
- context 'with ci_jobs_finder_refactor ff disabled' do
- before do
- stub_feature_flags(ci_jobs_finder_refactor: false)
- end
-
- context 'scope is present' do
- let(:jobs) { [job_1, job_2, job_3] }
-
- where(:scope, :index) do
- [
- ['pending', 0],
- ['running', 1],
- ['finished', 2]
- ]
- end
+ context 'scope is an array' do
+ let(:jobs) { [job_1, job_2, job_3] }
+ let(:params) {{ scope: ['running'] }}
- with_them do
- let(:params) { { scope: scope } }
-
- it { expect(subject).to match_array([jobs[index]]) }
- end
+ it 'filters by the job statuses in the scope' do
+ expect(subject).to match_array([job_2])
end
end
end
- context 'with ci_jobs_finder_refactor ff enabled' do
- before do
- stub_feature_flags(ci_jobs_finder_refactor: true)
- end
-
- context 'a project is present' do
- subject { described_class.new(current_user: user, project: project, params: params).execute }
-
- context 'user has access to the project' do
- before do
- project.add_maintainer(user)
- end
-
- it 'returns jobs for the specified project' do
- expect(subject).to match_array([job_3])
- end
- end
+ context 'a project is present' do
+ subject { described_class.new(current_user: user, project: project, params: params).execute }
- context 'user has no access to project builds' do
- before do
- project.add_guest(user)
- end
-
- it 'returns no jobs' do
- expect(subject).to be_empty
- end
+ context 'user has access to the project' do
+ before do
+ project.add_maintainer(user)
end
- context 'without user' do
- let(:user) { nil }
-
- it 'returns no jobs' do
- expect(subject).to be_empty
- end
+ it 'returns jobs for the specified project' do
+ expect(subject).to match_array([job_3])
end
end
- end
-
- context 'with ci_jobs_finder_refactor ff disabled' do
- before do
- stub_feature_flags(ci_jobs_finder_refactor: false)
- end
- context 'a project is present' do
- subject { described_class.new(current_user: user, project: project, params: params).execute }
- context 'user has access to the project' do
- before do
- project.add_maintainer(user)
- end
-
- it 'returns jobs for the specified project' do
- expect(subject).to match_array([job_3])
- end
+ context 'user has no access to project builds' do
+ before do
+ project.add_guest(user)
end
- context 'user has no access to project builds' do
- before do
- project.add_guest(user)
- end
-
- it 'returns no jobs' do
- expect(subject).to be_empty
- end
+ it 'returns no jobs' do
+ expect(subject).to be_empty
end
+ end
- context 'without user' do
- let(:user) { nil }
+ context 'without user' do
+ let(:user) { nil }
- it 'returns no jobs' do
- expect(subject).to be_empty
- end
+ it 'returns no jobs' do
+ expect(subject).to be_empty
end
end
end