diff options
Diffstat (limited to 'spec/lib/gitlab/ci/config_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/config_spec.rb | 88 |
1 files changed, 71 insertions, 17 deletions
diff --git a/spec/lib/gitlab/ci/config_spec.rb b/spec/lib/gitlab/ci/config_spec.rb index 525335cfea9..82ca8a29c5a 100644 --- a/spec/lib/gitlab/ci/config_spec.rb +++ b/spec/lib/gitlab/ci/config_spec.rb @@ -376,23 +376,6 @@ describe Gitlab::Ci::Config do end end - context 'when context expansion timeout is disabled' do - before do - allow_next_instance_of(Gitlab::Ci::Config::External::Context) do |instance| - allow(instance).to receive(:check_execution_time!).and_call_original - end - - allow(Feature) - .to receive(:enabled?) - .with(:ci_limit_yaml_expansion, project, default_enabled: true) - .and_return(false) - end - - it 'does not raises errors' do - expect { config }.not_to raise_error - end - end - describe 'external file version' do context 'when external local file SHA is defined' do it 'is using a defined value' do @@ -541,5 +524,76 @@ describe Gitlab::Ci::Config do end end end + + context 'when including file from artifact' do + let(:config) do + described_class.new( + gitlab_ci_yml, + project: nil, + sha: nil, + user: nil, + parent_pipeline: parent_pipeline) + end + + let(:gitlab_ci_yml) do + <<~HEREDOC + include: + - artifact: generated.yml + job: rspec + HEREDOC + end + + let(:parent_pipeline) { nil } + + context 'when used in the context of a child pipeline' do + # This job has ci_build_artifacts.zip artifact archive which + # contains generated.yml + let!(:job) { create(:ci_build, :artifacts, name: 'rspec', pipeline: parent_pipeline) } + let(:parent_pipeline) { create(:ci_pipeline) } + + it 'returns valid config' do + expect(config).to be_valid + end + + context 'when job key is missing' do + let(:gitlab_ci_yml) do + <<~HEREDOC + include: + - artifact: generated.yml + HEREDOC + end + + it 'raises an error' do + expect { config }.to raise_error( + described_class::ConfigError, + 'Job must be provided when including configs from artifacts' + ) + end + end + + context 'when artifact key is missing' do + let(:gitlab_ci_yml) do + <<~HEREDOC + include: + - job: rspec + HEREDOC + end + + it 'raises an error' do + expect { config }.to raise_error( + described_class::ConfigError, + /needs to match exactly one accessor!/ + ) + end + end + end + + it 'disallows the use in parent pipelines' do + expect { config }.to raise_error( + described_class::ConfigError, + 'Including configs from artifacts is only allowed when triggering child pipelines' + ) + end + end end end |