summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/external/mapper_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/ci/config/external/mapper_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/config/external/mapper_spec.rb77
1 files changed, 53 insertions, 24 deletions
diff --git a/spec/lib/gitlab/ci/config/external/mapper_spec.rb b/spec/lib/gitlab/ci/config/external/mapper_spec.rb
index f69feba5e59..2d2adf09a42 100644
--- a/spec/lib/gitlab/ci/config/external/mapper_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/mapper_spec.rb
@@ -17,10 +17,12 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
let(:file_content) do
<<~HEREDOC
- image: 'ruby:2.7'
+ image: 'image:1.0'
HEREDOC
end
+ subject(:mapper) { described_class.new(values, context) }
+
before do
stub_full_request(remote_url).to_return(body: file_content)
@@ -30,13 +32,13 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
end
describe '#process' do
- subject { described_class.new(values, context).process }
+ subject(:process) { mapper.process }
context "when single 'include' keyword is defined" do
context 'when the string is a local file' do
let(:values) do
{ include: local_file,
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'returns File instances' do
@@ -48,7 +50,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context 'when the key is a local file hash' do
let(:values) do
{ include: { 'local' => local_file },
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'returns File instances' do
@@ -59,7 +61,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context 'when the string is a remote file' do
let(:values) do
- { include: remote_url, image: 'ruby:2.7' }
+ { include: remote_url, image: 'image:1.0' }
end
it 'returns File instances' do
@@ -71,7 +73,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context 'when the key is a remote file hash' do
let(:values) do
{ include: { 'remote' => remote_url },
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'returns File instances' do
@@ -83,7 +85,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context 'when the key is a template file hash' do
let(:values) do
{ include: { 'template' => template_file },
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'returns File instances' do
@@ -98,7 +100,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
let(:remote_url) { 'https://gitlab.com/secret-file.yml' }
let(:values) do
{ include: { 'local' => local_file, 'remote' => remote_url },
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'returns ambigious specification error' do
@@ -109,7 +111,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context "when the key is a project's file" do
let(:values) do
{ include: { project: project.full_path, file: local_file },
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'returns File instances' do
@@ -121,7 +123,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context "when the key is project's files" do
let(:values) do
{ include: { project: project.full_path, file: [local_file, 'another_file_path.yml'] },
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'returns two File instances' do
@@ -135,7 +137,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context "when 'include' is defined as an array" do
let(:values) do
{ include: [remote_url, local_file],
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'returns Files instances' do
@@ -147,7 +149,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context "when 'include' is defined as an array of hashes" do
let(:values) do
{ include: [{ remote: remote_url }, { local: local_file }],
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'returns Files instances' do
@@ -158,7 +160,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context 'when it has ambigious match' do
let(:values) do
{ include: [{ remote: remote_url, local: local_file }],
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'returns ambigious specification error' do
@@ -170,7 +172,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context "when 'include' is not defined" do
let(:values) do
{
- image: 'ruby:2.7'
+ image: 'image:1.0'
}
end
@@ -185,11 +187,16 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
{ 'local' => local_file },
{ 'local' => local_file }
],
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'does not raise an exception' do
- expect { subject }.not_to raise_error
+ expect { process }.not_to raise_error
+ end
+
+ it 'has expanset with one' do
+ process
+ expect(mapper.expandset.size).to eq(1)
end
end
@@ -199,7 +206,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
{ 'local' => local_file },
{ 'remote' => remote_url }
],
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
before do
@@ -217,7 +224,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
{ 'local' => local_file },
{ 'remote' => remote_url }
],
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
before do
@@ -269,7 +276,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context 'defined as an array' do
let(:values) do
{ include: [full_local_file_path, remote_url],
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'expands the variable' do
@@ -281,7 +288,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context 'defined as an array of hashes' do
let(:values) do
{ include: [{ local: full_local_file_path }, { remote: remote_url }],
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'expands the variable' do
@@ -303,7 +310,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
context 'project name' do
let(:values) do
{ include: { project: '$CI_PROJECT_PATH', file: local_file },
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
it 'expands the variable', :aggregate_failures do
@@ -315,7 +322,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
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' }
+ image: 'image:1.0' }
end
it 'expands the variable' do
@@ -327,7 +334,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
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' }
+ image: 'image:1.0' }
end
it 'does not invoke expansion for the variable', :aggregate_failures do
@@ -365,7 +372,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
let(:values) do
{ include: [{ remote: remote_url },
{ local: local_file, rules: [{ if: "$CI_PROJECT_ID == '#{project_id}'" }] }],
- image: 'ruby:2.7' }
+ image: 'image:1.0' }
end
context 'when the rules matches' do
@@ -385,5 +392,27 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
end
end
end
+
+ context "when locations are same after masking variables" do
+ let(:variables) do
+ Gitlab::Ci::Variables::Collection.new([
+ { 'key' => 'GITLAB_TOKEN', 'value' => 'secret-file1', 'masked' => true },
+ { 'key' => 'GITLAB_TOKEN', 'value' => 'secret-file2', 'masked' => true }
+ ])
+ end
+
+ let(:values) do
+ { include: [
+ { 'local' => 'hello/secret-file1.yml' },
+ { 'local' => 'hello/secret-file2.yml' }
+ ],
+ image: 'ruby:2.7' }
+ end
+
+ it 'has expanset with two' do
+ process
+ expect(mapper.expandset.size).to eq(2)
+ end
+ end
end
end