Commit 9b1bb282 authored by Sean McGivern's avatar Sean McGivern

Merge branch '199736-deprecate-any-report-artifact-for-type' into 'master'

Resolve "Delete `pipeline.any_report_artifact_for_type` method"

See merge request gitlab-org/gitlab!24395
parents 12d17113 9a4b4cee
...@@ -159,10 +159,6 @@ module EE ...@@ -159,10 +159,6 @@ module EE
::Ci::Build.id_in(dep_id) ::Ci::Build.id_in(dep_id)
end end
def name_in?(names)
name.in?(Array(names))
end
def parse_security_artifact_blob(security_report, blob) def parse_security_artifact_blob(security_report, blob)
report_clone = security_report.clone_as_blank report_clone = security_report.clone_as_blank
::Gitlab::Ci::Parsers.fabricate!(security_report.type).parse!(blob, report_clone) ::Gitlab::Ci::Parsers.fabricate!(security_report.type).parse!(blob, report_clone)
......
...@@ -116,12 +116,6 @@ module EE ...@@ -116,12 +116,6 @@ module EE
.last .last
end end
def any_report_artifact_for_type(file_type)
return unless available_licensed_report_type?(file_type)
job_artifacts.where(file_type: ::Ci::JobArtifact.file_types[file_type]).last
end
def expose_license_scanning_data? def expose_license_scanning_data?
batch_lookup_report_artifact_for_file_type(:license_scanning).present? batch_lookup_report_artifact_for_file_type(:license_scanning).present?
end end
......
...@@ -19,10 +19,10 @@ module EE ...@@ -19,10 +19,10 @@ module EE
end end
def expose_security_dashboard? def expose_security_dashboard?
any_report_artifact_for_type(:sast) || batch_lookup_report_artifact_for_file_type(:sast) ||
any_report_artifact_for_type(:dependency_scanning) || batch_lookup_report_artifact_for_file_type(:dependency_scanning) ||
any_report_artifact_for_type(:dast) || batch_lookup_report_artifact_for_file_type(:dast) ||
any_report_artifact_for_type(:container_scanning) batch_lookup_report_artifact_for_file_type(:container_scanning)
end end
def downloadable_path_for_report_type(file_type) def downloadable_path_for_report_type(file_type)
......
...@@ -63,63 +63,6 @@ describe Ci::Pipeline do ...@@ -63,63 +63,6 @@ describe Ci::Pipeline do
end end
end end
shared_examples 'unlicensed report type' do
context 'when there is no licensed feature for artifact file type' do
it 'returns the artifact' do
expect(subject).to eq(expected)
end
end
end
shared_examples 'licensed report type' do |feature|
context 'when licensed features is NOT available' do
it 'returns nil' do
allow(pipeline.project).to receive(:feature_available?)
.with(feature).and_return(false)
expect(subject).to be_nil
end
end
context 'when licensed feature is available' do
it 'returns the artifact' do
allow(pipeline.project).to receive(:feature_available?)
.with(feature).and_return(true)
expect(subject).to eq(expected)
end
end
end
shared_examples 'multi-licensed report type' do |features|
context 'when NONE of the licensed features are available' do
it 'returns nil' do
features.each do |feature|
allow(pipeline.project).to receive(:feature_available?)
.with(feature).and_return(false)
end
expect(subject).to be_nil
end
end
context 'when at least one licensed feature is available' do
features.each do |feature|
it 'returns the artifact' do
allow(pipeline.project).to receive(:feature_available?)
.with(feature).and_return(true)
features.reject { |f| f == feature }.each do |disabled_feature|
allow(pipeline.project).to receive(:feature_available?)
.with(disabled_feature).and_return(true)
end
expect(subject).to eq(expected)
end
end
end
end
describe '#batch_lookup_report_artifact_for_file_type' do describe '#batch_lookup_report_artifact_for_file_type' do
subject(:artifact) { pipeline.batch_lookup_report_artifact_for_file_type(file_type) } subject(:artifact) { pipeline.batch_lookup_report_artifact_for_file_type(file_type) }
...@@ -173,34 +116,6 @@ describe Ci::Pipeline do ...@@ -173,34 +116,6 @@ describe Ci::Pipeline do
end end
end end
describe '#any_report_artifact_for_type' do
let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:artifact) do
create(:ci_job_artifact,
job: build,
file_type: file_type,
file_format: ::Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS[file_type])
end
subject { pipeline.any_report_artifact_for_type(file_type) }
described_class::REPORT_LICENSED_FEATURES.each do |file_type, licensed_features|
context "for file_type: #{file_type}" do
let(:file_type) { file_type }
let(:expected) { artifact }
if licensed_features.nil?
it_behaves_like 'unlicensed report type'
elsif licensed_features.size == 1
it_behaves_like 'licensed report type', licensed_features.first
else
it_behaves_like 'multi-licensed report type', licensed_features
end
end
end
end
describe '#expose_license_scanning_data?' do describe '#expose_license_scanning_data?' do
subject { pipeline.expose_license_scanning_data? } subject { pipeline.expose_license_scanning_data? }
......
...@@ -4,13 +4,11 @@ require 'spec_helper' ...@@ -4,13 +4,11 @@ require 'spec_helper'
describe Ci::PipelinePresenter do describe Ci::PipelinePresenter do
let_it_be(:project, reload: true) { create(:project) } let_it_be(:project, reload: true) { create(:project) }
let_it_be(:pipeline, reload: true) { create(:ci_pipeline, project: project) } let_it_be(:pipeline, reload: true) { create(:ee_ci_pipeline, project: project) }
subject(:presenter) do let(:presenter) { described_class.new(pipeline) }
described_class.new(pipeline)
end
context '#failure_reason' do describe '#failure_reason' do
context 'when pipeline has failure reason' do context 'when pipeline has failure reason' do
it 'represents a failure reason sentence' do it 'represents a failure reason sentence' do
pipeline.failure_reason = :activity_limit_exceeded pipeline.failure_reason = :activity_limit_exceeded
...@@ -26,4 +24,40 @@ describe Ci::PipelinePresenter do ...@@ -26,4 +24,40 @@ describe Ci::PipelinePresenter do
end end
end end
end end
describe '#expose_security_dashboard?' do
subject { presenter.expose_security_dashboard? }
context 'when features are available' do
before do
stub_licensed_features(dependency_scanning: true, license_management: true)
end
context 'when there is an artifact of a right type' do
let!(:build) { create(:ee_ci_build, :dependency_scanning, pipeline: pipeline) }
it { is_expected.to be_truthy }
end
context 'when there is an artifact of a wrong type' do
let!(:build) { create(:ee_ci_build, :license_scanning, pipeline: pipeline) }
it { is_expected.to be_falsey }
end
context 'when there is no found artifact' do
let!(:build) { create(:ee_ci_build, pipeline: pipeline) }
it { is_expected.to be_falsey }
end
end
context 'when features are disabled' do
context 'when there is an artifact of a right type' do
let!(:build) { create(:ee_ci_build, :dependency_scanning, pipeline: pipeline) }
it { is_expected.to be_falsey }
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment