Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/config/loader/multi_doc_yaml_spec.rb')
-rw-r--r--spec/lib/gitlab/config/loader/multi_doc_yaml_spec.rb99
1 files changed, 99 insertions, 0 deletions
diff --git a/spec/lib/gitlab/config/loader/multi_doc_yaml_spec.rb b/spec/lib/gitlab/config/loader/multi_doc_yaml_spec.rb
new file mode 100644
index 00000000000..bae98f9bc35
--- /dev/null
+++ b/spec/lib/gitlab/config/loader/multi_doc_yaml_spec.rb
@@ -0,0 +1,99 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Config::Loader::MultiDocYaml, feature_category: :pipeline_authoring do
+ let(:loader) { described_class.new(yml, max_documents: 2) }
+
+ describe '#load!' do
+ let(:yml) do
+ <<~YAML
+ spec:
+ inputs:
+ test_input:
+ ---
+ test_job:
+ script: echo "$[[ inputs.test_input ]]"
+ YAML
+ end
+
+ it 'returns the loaded YAML with all keys as symbols' do
+ expect(loader.load!).to eq([
+ { spec: { inputs: { test_input: nil } } },
+ { test_job: { script: 'echo "$[[ inputs.test_input ]]"' } }
+ ])
+ end
+
+ context 'when the YAML file is empty' do
+ let(:yml) { '' }
+
+ it 'returns an empty array' do
+ expect(loader.load!).to be_empty
+ end
+ end
+
+ context 'when the parsed YAML is too big' do
+ let(:yml) do
+ <<~YAML
+ a: &a ["lol","lol","lol","lol","lol","lol","lol","lol","lol"]
+ b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]
+ c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b]
+ d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c]
+ e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d]
+ f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e]
+ g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f]
+ h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g]
+ i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h]
+ ---
+ a: &a ["lol","lol","lol","lol","lol","lol","lol","lol","lol"]
+ b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]
+ c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b]
+ d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c]
+ e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d]
+ f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e]
+ g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f]
+ h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g]
+ i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h]
+ YAML
+ end
+
+ it 'raises a DataTooLargeError' do
+ expect { loader.load! }.to raise_error(described_class::DataTooLargeError, 'The parsed YAML is too big')
+ end
+ end
+
+ context 'when a document is not a hash' do
+ let(:yml) do
+ <<~YAML
+ not_a_hash
+ ---
+ test_job:
+ script: echo "$[[ inputs.test_input ]]"
+ YAML
+ end
+
+ it 'raises a NotHashError' do
+ expect { loader.load! }.to raise_error(described_class::NotHashError, 'Invalid configuration format')
+ end
+ end
+
+ context 'when there are too many documents' do
+ let(:yml) do
+ <<~YAML
+ a: b
+ ---
+ c: d
+ ---
+ e: f
+ YAML
+ end
+
+ it 'raises a TooManyDocumentsError' do
+ expect { loader.load! }.to raise_error(
+ described_class::TooManyDocumentsError,
+ 'The parsed YAML has too many documents'
+ )
+ end
+ end
+ end
+end