summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
committerRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
commit6438df3a1e0fb944485cebf07976160184697d72 (patch)
tree00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/lib/gitlab/ci/config
parent42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff)
downloadgitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/lib/gitlab/ci/config')
-rw-r--r--spec/lib/gitlab/ci/config/entry/artifacts_spec.rb17
-rw-r--r--spec/lib/gitlab/ci/config/entry/variables_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/config/external/file/local_spec.rb6
-rw-r--r--spec/lib/gitlab/ci/config/external/file/project_spec.rb6
-rw-r--r--spec/lib/gitlab/ci/config/external/mapper_spec.rb126
-rw-r--r--spec/lib/gitlab/ci/config/external/processor_spec.rb13
6 files changed, 140 insertions, 30 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/artifacts_spec.rb b/spec/lib/gitlab/ci/config/entry/artifacts_spec.rb
index 028dcd3e1e6..0e6d5b6c311 100644
--- a/spec/lib/gitlab/ci/config/entry/artifacts_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/artifacts_spec.rb
@@ -36,6 +36,14 @@ RSpec.describe Gitlab::Ci::Config::Entry::Artifacts do
expect(entry.value).to eq config
end
end
+
+ context "when value includes 'public' keyword" do
+ let(:config) { { paths: %w[results.txt], public: false } }
+
+ it 'returns general artifact and report-type artifacts configuration' do
+ expect(entry.value).to eq config
+ end
+ end
end
context 'when entry value is not correct' do
@@ -67,6 +75,15 @@ RSpec.describe Gitlab::Ci::Config::Entry::Artifacts do
end
end
+ context "when 'public' is not a boolean" do
+ let(:config) { { paths: %w[results.txt], public: 'false' } }
+
+ it 'reports error' do
+ expect(entry.errors)
+ .to include 'artifacts public should be a boolean value'
+ end
+ end
+
context "when 'expose_as' is not a string" do
let(:config) { { paths: %w[results.txt], expose_as: 1 } }
diff --git a/spec/lib/gitlab/ci/config/entry/variables_spec.rb b/spec/lib/gitlab/ci/config/entry/variables_spec.rb
index 426a38e2ef7..78d37e228df 100644
--- a/spec/lib/gitlab/ci/config/entry/variables_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/variables_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::Entry::Variables do
let(:metadata) { {} }
- subject { described_class.new(config, metadata) }
+ subject { described_class.new(config, **metadata) }
shared_examples 'valid config' do
describe '#value' do
diff --git a/spec/lib/gitlab/ci/config/external/file/local_spec.rb b/spec/lib/gitlab/ci/config/external/file/local_spec.rb
index fdd29afe2d6..7e39fae7b9b 100644
--- a/spec/lib/gitlab/ci/config/external/file/local_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/file/local_spec.rb
@@ -16,7 +16,8 @@ RSpec.describe Gitlab::Ci::Config::External::File::Local do
project: project,
sha: sha,
user: user,
- parent_pipeline: parent_pipeline
+ parent_pipeline: parent_pipeline,
+ variables: project.predefined_variables.to_runner_variables
}
end
@@ -131,7 +132,8 @@ RSpec.describe Gitlab::Ci::Config::External::File::Local do
user: user,
project: project,
sha: sha,
- parent_pipeline: parent_pipeline)
+ parent_pipeline: parent_pipeline,
+ variables: project.predefined_variables.to_runner_variables)
end
end
diff --git a/spec/lib/gitlab/ci/config/external/file/project_spec.rb b/spec/lib/gitlab/ci/config/external/file/project_spec.rb
index a5e4e27df6f..0e8851ba915 100644
--- a/spec/lib/gitlab/ci/config/external/file/project_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/file/project_spec.rb
@@ -16,7 +16,8 @@ RSpec.describe Gitlab::Ci::Config::External::File::Project do
project: context_project,
sha: '12345',
user: context_user,
- parent_pipeline: parent_pipeline
+ parent_pipeline: parent_pipeline,
+ variables: project.predefined_variables.to_runner_variables
}
end
@@ -165,7 +166,8 @@ RSpec.describe Gitlab::Ci::Config::External::File::Project do
user: user,
project: project,
sha: project.commit('master').id,
- parent_pipeline: parent_pipeline)
+ parent_pipeline: parent_pipeline,
+ variables: project.predefined_variables.to_runner_variables)
end
end
diff --git a/spec/lib/gitlab/ci/config/external/mapper_spec.rb b/spec/lib/gitlab/ci/config/external/mapper_spec.rb
index 7ad57827e30..4fdaaca8316 100644
--- a/spec/lib/gitlab/ci/config/external/mapper_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/mapper_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
let(:local_file) { '/lib/gitlab/ci/templates/non-existent-file.yml' }
let(:remote_url) { 'https://gitlab.com/gitlab-org/gitlab-foss/blob/1234/.gitlab-ci-1.yml' }
let(:template_file) { 'Auto-DevOps.gitlab-ci.yml' }
- let(:context_params) { { project: project, sha: '123456', user: user } }
+ let(:context_params) { { project: project, sha: '123456', user: user, variables: project.predefined_variables.to_runner_variables } }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
let(:file_content) do
@@ -124,17 +124,6 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
an_instance_of(Gitlab::Ci::Config::External::File::Project),
an_instance_of(Gitlab::Ci::Config::External::File::Project))
end
-
- context 'when FF ci_include_multiple_files_from_project is disabled' do
- before do
- stub_feature_flags(ci_include_multiple_files_from_project: false)
- end
-
- it 'returns a File instance' do
- expect(subject).to contain_exactly(
- an_instance_of(Gitlab::Ci::Config::External::File::Project))
- end
- end
end
end
@@ -236,5 +225,118 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
end
end
end
+
+ context "when 'include' section uses project variable" do
+ let(:full_local_file_path) { '$CI_PROJECT_PATH' + local_file }
+
+ context 'when local file is included as a single string' do
+ let(:values) do
+ { include: full_local_file_path }
+ end
+
+ it 'expands the variable', :aggregate_failures do
+ expect(subject[0].location).to eq(project.full_path + local_file)
+ expect(subject).to contain_exactly(an_instance_of(Gitlab::Ci::Config::External::File::Local))
+ end
+ end
+
+ context 'when remote file is included as a single string' do
+ let(:remote_url) { "#{Gitlab.config.gitlab.url}/radio/.gitlab-ci.yml" }
+
+ let(:values) do
+ { include: '$CI_SERVER_URL/radio/.gitlab-ci.yml' }
+ end
+
+ it 'expands the variable', :aggregate_failures do
+ expect(subject[0].location).to eq(remote_url)
+ expect(subject).to contain_exactly(an_instance_of(Gitlab::Ci::Config::External::File::Remote))
+ end
+ end
+
+ context 'defined as an array' do
+ let(:values) do
+ { include: [full_local_file_path, remote_url],
+ image: 'ruby:2.7' }
+ end
+
+ it 'expands the variable' do
+ expect(subject[0].location).to eq(project.full_path + local_file)
+ expect(subject[1].location).to eq(remote_url)
+ end
+ end
+
+ context 'defined as an array of hashes' do
+ let(:values) do
+ { include: [{ local: full_local_file_path }, { remote: remote_url }],
+ image: 'ruby:2.7' }
+ end
+
+ it 'expands the variable' do
+ expect(subject[0].location).to eq(project.full_path + local_file)
+ expect(subject[1].location).to eq(remote_url)
+ end
+ end
+
+ context 'local file hash' do
+ let(:values) do
+ { include: { 'local' => full_local_file_path } }
+ end
+
+ it 'expands the variable' do
+ expect(subject[0].location).to eq(project.full_path + local_file)
+ end
+ end
+
+ context 'project name' do
+ let(:values) do
+ { include: { project: '$CI_PROJECT_PATH', file: local_file },
+ image: 'ruby:2.7' }
+ end
+
+ it 'expands the variable', :aggregate_failures do
+ expect(subject[0].project_name).to eq(project.full_path)
+ expect(subject).to contain_exactly(an_instance_of(Gitlab::Ci::Config::External::File::Project))
+ end
+ end
+
+ context 'with multiple files' do
+ let(:values) do
+ { include: { project: project.full_path, file: [full_local_file_path, 'another_file_path.yml'] },
+ image: 'ruby:2.7' }
+ end
+
+ it 'expands the variable' do
+ expect(subject[0].location).to eq(project.full_path + local_file)
+ expect(subject[1].location).to eq('another_file_path.yml')
+ end
+ end
+
+ context 'when include variable has an unsupported type for variable expansion' do
+ let(:values) do
+ { include: { project: project.id, file: local_file },
+ image: 'ruby:2.7' }
+ end
+
+ it 'does not invoke expansion for the variable', :aggregate_failures do
+ expect(ExpandVariables).not_to receive(:expand).with(project.id, context_params[:variables])
+
+ expect { subject }.to raise_error(described_class::AmbigiousSpecificationError)
+ end
+ end
+
+ context 'when feature flag is turned off' do
+ let(:values) do
+ { include: full_local_file_path }
+ end
+
+ before do
+ stub_feature_flags(variables_in_include_section_ci: false)
+ end
+
+ it 'does not expand the variables' do
+ expect(subject[0].location).to eq('$CI_PROJECT_PATH' + local_file)
+ end
+ end
+ end
end
end
diff --git a/spec/lib/gitlab/ci/config/external/processor_spec.rb b/spec/lib/gitlab/ci/config/external/processor_spec.rb
index 150a2ec2929..d2d7116bb12 100644
--- a/spec/lib/gitlab/ci/config/external/processor_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/processor_spec.rb
@@ -365,19 +365,6 @@ RSpec.describe Gitlab::Ci::Config::External::Processor do
output = processor.perform
expect(output.keys).to match_array([:image, :my_build, :my_test])
end
-
- context 'when FF ci_include_multiple_files_from_project is disabled' do
- before do
- stub_feature_flags(ci_include_multiple_files_from_project: false)
- end
-
- it 'raises an error' do
- expect { processor.perform }.to raise_error(
- described_class::IncludeError,
- 'Included file `["/templates/my-build.yml", "/templates/my-test.yml"]` needs to be a string'
- )
- end
- end
end
end
end