diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-14 03:08:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-14 03:08:51 +0000 |
commit | 962711501ff8e5a004c700b97a367930ed5a1f20 (patch) | |
tree | 8be5b4d4de0cd0bdd5c61be727d67d1171c865d1 /spec/services | |
parent | 13d294a8d8be05421e7d5e34577033ba5b34059c (diff) | |
download | gitlab-ce-962711501ff8e5a004c700b97a367930ed5a1f20.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/ci/job_artifacts/create_service_spec.rb | 28 | ||||
-rw-r--r-- | spec/services/issues/related_branches_service_spec.rb | 93 |
2 files changed, 26 insertions, 95 deletions
diff --git a/spec/services/ci/job_artifacts/create_service_spec.rb b/spec/services/ci/job_artifacts/create_service_spec.rb index 01f240805f5..b7a810ce47e 100644 --- a/spec/services/ci/job_artifacts/create_service_spec.rb +++ b/spec/services/ci/job_artifacts/create_service_spec.rb @@ -30,14 +30,6 @@ RSpec.describe Ci::JobArtifacts::CreateService do UploadedFile.new(upload.path, **params) end - def unique_metrics_report_uploaders - Gitlab::UsageDataCounters::HLLRedisCounter.unique_events( - event_names: described_class::METRICS_REPORT_UPLOAD_EVENT_NAME, - start_date: 2.weeks.ago, - end_date: 2.weeks.from_now - ) - end - describe '#execute' do subject { service.execute(artifacts_file, params, metadata_file: metadata_file) } @@ -61,12 +53,6 @@ RSpec.describe Ci::JobArtifacts::CreateService do expect(new_artifact.locked).to eq(job.pipeline.locked) end - it 'does not track the job user_id' do - subject - - expect(unique_metrics_report_uploaders).to eq(0) - end - context 'when metadata file is also uploaded' do let(:metadata_file) do file_to_upload('spec/fixtures/ci_build_artifacts_metadata.gz', sha256: artifacts_sha256) @@ -188,20 +174,6 @@ RSpec.describe Ci::JobArtifacts::CreateService do end end - context 'when artifact_type is metrics' do - before do - allow(job).to receive(:user_id).and_return(123) - end - - let(:params) { { 'artifact_type' => 'metrics', 'artifact_format' => 'gzip' }.with_indifferent_access } - - it 'tracks the job user_id' do - subject - - expect(unique_metrics_report_uploaders).to eq(1) - end - end - shared_examples 'rescues object storage error' do |klass, message, expected_message| it "handles #{klass}" do allow_next_instance_of(JobArtifactUploader) do |uploader| diff --git a/spec/services/issues/related_branches_service_spec.rb b/spec/services/issues/related_branches_service_spec.rb index 7a4bae7f852..95d456c1b05 100644 --- a/spec/services/issues/related_branches_service_spec.rb +++ b/spec/services/issues/related_branches_service_spec.rb @@ -3,88 +3,47 @@ require 'spec_helper' RSpec.describe Issues::RelatedBranchesService do + let_it_be(:project) { create(:project, :repository, :public, public_builds: false) } let_it_be(:developer) { create(:user) } - let_it_be(:issue) { create(:issue) } + let_it_be(:issue) { create(:issue, project: project) } let(:user) { developer } - subject { described_class.new(project: issue.project, current_user: user) } + subject { described_class.new(project: project, current_user: user) } - before do - issue.project.add_developer(developer) + before_all do + project.add_developer(developer) end describe '#execute' do - let(:sha) { 'abcdef' } - let(:repo) { issue.project.repository } - let(:project) { issue.project } let(:branch_info) { subject.execute(issue) } - def make_branch - double('Branch', dereferenced_target: double('Target', sha: sha)) - end - - before do - allow(repo).to receive(:branch_names).and_return(branch_names) - end - - context 'no branches are available' do - let(:branch_names) { [] } - - it 'returns an empty array' do - expect(branch_info).to be_empty - end - end - context 'branches are available' do - let(:missing_branch) { "#{issue.to_branch_name}-missing" } - let(:unreadable_branch_name) { "#{issue.to_branch_name}-unreadable" } - let(:pipeline) { build(:ci_pipeline, :success, project: project) } - let(:unreadable_pipeline) { build(:ci_pipeline, :running) } - - let(:branch_names) do - [ - generate(:branch), - "#{issue.iid}doesnt-match", - issue.to_branch_name, - missing_branch, - unreadable_branch_name - ] - end + let_it_be(:pipeline) { create(:ci_pipeline, :success, project: project, ref: issue.to_branch_name) } - before do - { - issue.to_branch_name => pipeline, - unreadable_branch_name => unreadable_pipeline - }.each do |name, pipeline| - allow(repo).to receive(:find_branch).with(name).and_return(make_branch) - allow(project).to receive(:latest_pipeline).with(name, sha).and_return(pipeline) - end + before_all do + project.repository.create_branch(issue.to_branch_name, pipeline.sha) + project.repository.create_branch("#{issue.iid}doesnt-match", project.repository.root_ref) + project.repository.create_branch("#{issue.iid}-0-stable", project.repository.root_ref) - allow(repo).to receive(:find_branch).with(missing_branch).and_return(nil) + project.repository.add_tag(developer, issue.to_branch_name, pipeline.sha) end - it 'selects relevant branches, along with pipeline status where available' do - expect(branch_info).to contain_exactly( - { name: issue.to_branch_name, pipeline_status: an_instance_of(Gitlab::Ci::Status::Success) }, - { name: missing_branch, pipeline_status: be_nil }, - { name: unreadable_branch_name, pipeline_status: be_nil } - ) + context 'when user has access to pipelines' do + it 'selects relevant branches, along with pipeline status' do + expect(branch_info).to contain_exactly( + { name: issue.to_branch_name, pipeline_status: an_instance_of(Gitlab::Ci::Status::Success) } + ) + end end - context 'the user has access to otherwise unreadable pipelines' do - let(:user) { create(:admin) } + context 'when user does not have access to pipelines' do + let(:user) { create(:user) } - context 'when admin mode is enabled', :enable_admin_mode do - it 'returns info a developer could not see' do - expect(branch_info.pluck(:pipeline_status)).to include(an_instance_of(Gitlab::Ci::Status::Running)) - end - end - - context 'when admin mode is disabled' do - it 'does not return info a developer could not see' do - expect(branch_info.pluck(:pipeline_status)).not_to include(an_instance_of(Gitlab::Ci::Status::Running)) - end + it 'returns branches without pipeline status' do + expect(branch_info).to contain_exactly( + { name: issue.to_branch_name, pipeline_status: nil } + ) end end @@ -103,10 +62,10 @@ RSpec.describe Issues::RelatedBranchesService do end end - context 'one of the branches is stable' do - let(:branch_names) { ["#{issue.iid}-0-stable"] } + context 'no branches are available' do + let(:project) { create(:project, :empty_repo) } - it 'is excluded' do + it 'returns an empty array' do expect(branch_info).to be_empty end end |