summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/ci/config_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/config_spec.rb96
1 files changed, 96 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/config_spec.rb b/spec/lib/gitlab/ci/config_spec.rb
index 839b4f9261d..b254f9af2f1 100644
--- a/spec/lib/gitlab/ci/config_spec.rb
+++ b/spec/lib/gitlab/ci/config_spec.rb
@@ -7,6 +7,11 @@ describe Gitlab::Ci::Config do
set(:user) { create(:user) }
+ before do
+ allow_any_instance_of(Gitlab::Ci::Config::External::Context)
+ .to receive(:check_execution_time!)
+ end
+
let(:config) do
described_class.new(yml, project: nil, sha: nil, user: nil)
end
@@ -46,6 +51,54 @@ describe Gitlab::Ci::Config do
end
end
end
+
+ describe '#stages' do
+ subject(:subject) { config.stages }
+
+ context 'with default stages' do
+ let(:default_stages) do
+ %w[.pre build test deploy .post]
+ end
+
+ it { is_expected.to eq default_stages }
+ end
+
+ context 'with custom stages' do
+ let(:yml) do
+ <<-EOS
+ stages:
+ - stage1
+ - stage2
+ job1:
+ stage: stage1
+ script:
+ - ls
+ EOS
+ end
+
+ it { is_expected.to eq %w[.pre stage1 stage2 .post] }
+ end
+
+ context 'with feature disabled' do
+ before do
+ stub_feature_flags(ci_pre_post_pipeline_stages: false)
+ end
+
+ let(:yml) do
+ <<-EOS
+ stages:
+ - stage1
+ - stage2
+ job1:
+ stage: stage1
+ script:
+ - ls
+ EOS
+ end
+
+ it { is_expected.to eq %w[stage1 stage2] }
+ end
+ end
end
context 'when using extendable hash' do
@@ -303,6 +356,49 @@ describe Gitlab::Ci::Config do
end
end
+ context "when it takes too long to evaluate includes" do
+ before do
+ allow_any_instance_of(Gitlab::Ci::Config::External::Context)
+ .to receive(:check_execution_time!)
+ .and_call_original
+
+ allow_any_instance_of(Gitlab::Ci::Config::External::Context)
+ .to receive(:set_deadline)
+ .with(described_class::TIMEOUT_SECONDS)
+ .and_call_original
+
+ allow_any_instance_of(Gitlab::Ci::Config::External::Context)
+ .to receive(:execution_expired?)
+ .and_return(true)
+ end
+
+ it 'raises error TimeoutError' do
+ expect(Gitlab::Sentry).to receive(:track_exception)
+
+ expect { config }.to raise_error(
+ described_class::ConfigError,
+ 'Resolving config took longer than expected'
+ )
+ end
+ end
+
+ context 'when context expansion timeout is disabled' do
+ before do
+ allow_any_instance_of(Gitlab::Ci::Config::External::Context)
+ .to receive(:check_execution_time!)
+ .and_call_original
+
+ 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