Commit 0910f60a authored by Philip Cunningham's avatar Philip Cunningham

Raise error when non-dangling builds use YAML blob

Captures invariant that YAML blobs are for dangling builds only.
parent e982a73d
......@@ -90,6 +90,10 @@ module Gitlab
metrics.pipeline_size_histogram
.observe({ source: pipeline.source.to_s }, pipeline.total_size)
end
def dangling_build?
%i[ondemand_dast_scan webide].include?(source)
end
end
end
end
......
......@@ -7,9 +7,12 @@ module Gitlab
module Config
class Content
class Parameter < Source
UnsupportedSourceError = Class.new(StandardError)
def content
strong_memoize(:content) do
next unless command.content.present?
raise UnsupportedSourceError, "#{command.source} not a dangling build" unless command.dangling_build?
command.content
end
......
......@@ -270,4 +270,29 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Command do
it { is_expected. to eq(true) }
end
end
describe '#dangling_build?' do
let(:project) { create(:project, :repository) }
let(:command) { described_class.new(project: project, source: source) }
subject { command.dangling_build? }
context 'when source is :webide' do
let(:source) { :webide }
it { is_expected.to eq(true) }
end
context 'when source is :ondemand_dast_scan' do
let(:source) { :ondemand_dast_scan }
it { is_expected.to eq(true) }
end
context 'when source something else' do
let(:source) { :web }
it { is_expected.to eq(false) }
end
end
end
......@@ -6,7 +6,8 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Config::Content do
let(:project) { create(:project, ci_config_path: ci_config_path) }
let(:pipeline) { build(:ci_pipeline, project: project) }
let(:content) { nil }
let(:command) { Gitlab::Ci::Pipeline::Chain::Command.new(project: project, content: content) }
let(:source) { :push }
let(:command) { Gitlab::Ci::Pipeline::Chain::Command.new(project: project, content: content, source: source) }
subject { described_class.new(pipeline, command) }
......@@ -143,6 +144,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Config::Content do
end
context 'when config is passed as a parameter' do
let(:source) { :ondemand_dast_scan }
let(:ci_config_path) { nil }
let(:content) do
<<~EOY
......
......@@ -28,23 +28,34 @@ RSpec.describe Ci::CreatePipelineService do
end
describe '#execute' do
subject { service.execute(:web, content: content) }
context 'when source is a dangling build' do
subject { service.execute(:ondemand_dast_scan, content: content) }
context 'parameter config content' do
it 'creates a pipeline' do
expect(subject).to be_persisted
end
context 'parameter config content' do
it 'creates a pipeline' do
expect(subject).to be_persisted
end
it 'creates builds with the correct names' do
expect(subject.builds.pluck(:name)).to match_array %w[dast]
end
it 'creates builds with the correct names' do
expect(subject.builds.pluck(:name)).to match_array %w[dast]
end
it 'creates stages with the correct names' do
expect(subject.stages.pluck(:name)).to match_array %w[dast]
end
it 'creates stages with the correct names' do
expect(subject.stages.pluck(:name)).to match_array %w[dast]
it 'sets the correct config source' do
expect(subject.config_source).to eq 'parameter_source'
end
end
end
context 'when source is not a dangling build' do
subject { service.execute(:web, content: content) }
it 'sets the correct config source' do
expect(subject.config_source).to eq 'parameter_source'
it 'raises an exception' do
klass = Gitlab::Ci::Pipeline::Chain::Config::Content::Parameter::UnsupportedSourceError
expect { subject }.to raise_error(klass)
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