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/ci/variables/collection_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/variables/collection_spec.rb150
1 files changed, 51 insertions, 99 deletions
diff --git a/spec/lib/gitlab/ci/variables/collection_spec.rb b/spec/lib/gitlab/ci/variables/collection_spec.rb
index 10b8f0065d9..4ee122cc607 100644
--- a/spec/lib/gitlab/ci/variables/collection_spec.rb
+++ b/spec/lib/gitlab/ci/variables/collection_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::Ci::Variables::Collection do
+RSpec.describe Gitlab::Ci::Variables::Collection, feature_category: :pipeline_authoring do
describe '.new' do
it 'can be initialized with an array' do
variable = { key: 'VAR', value: 'value', public: true, masked: false }
@@ -295,69 +295,6 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
end
end
- describe '#expand_value' do
- let(:collection) do
- Gitlab::Ci::Variables::Collection.new
- .append(key: 'CI_JOB_NAME', value: 'test-1')
- .append(key: 'CI_BUILD_ID', value: '1')
- .append(key: 'TEST1', value: 'test-3')
- .append(key: 'FILEVAR1', value: 'file value 1', file: true)
- end
-
- context 'table tests' do
- using RSpec::Parameterized::TableSyntax
-
- where do
- {
- "empty value": {
- value: '',
- result: ''
- },
- "simple expansions": {
- value: 'key$TEST1-$CI_BUILD_ID',
- result: 'keytest-3-1'
- },
- "complex expansion": {
- value: 'key${TEST1}-${CI_JOB_NAME}',
- result: 'keytest-3-test-1'
- },
- "missing variable not keeping original": {
- value: 'key${MISSING_VAR}-${CI_JOB_NAME}',
- result: 'key-test-1'
- },
- "missing variable keeping original": {
- value: 'key${MISSING_VAR}-${CI_JOB_NAME}',
- result: 'key${MISSING_VAR}-test-1',
- keep_undefined: true
- },
- "escaped characters are kept intact": {
- value: 'key-$TEST1-%%HOME%%-$${HOME}',
- result: 'key-test-3-%%HOME%%-$${HOME}'
- },
- "file variable with expand_file_refs: true": {
- value: 'key-$FILEVAR1-$TEST1',
- result: 'key-file value 1-test-3'
- },
- "file variable with expand_file_refs: false": {
- value: 'key-$FILEVAR1-$TEST1',
- result: 'key-$FILEVAR1-test-3',
- expand_file_refs: false
- }
- }
- end
-
- with_them do
- let(:options) { { keep_undefined: keep_undefined, expand_file_refs: expand_file_refs }.compact }
-
- subject(:expanded_result) { collection.expand_value(value, **options) }
-
- it 'matches expected expansion' do
- is_expected.to eq(result)
- end
- end
- end
- end
-
describe '#sort_and_expand_all' do
context 'table tests' do
using RSpec::Parameterized::TableSyntax
@@ -369,6 +306,14 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
keep_undefined: false,
result: []
},
+ "empty string": {
+ variables: [
+ { key: 'variable', value: '' }
+ ],
+ result: [
+ { key: 'variable', value: '' }
+ ]
+ },
"simple expansions": {
variables: [
{ key: 'variable', value: 'value' },
@@ -560,13 +505,42 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
{ key: 'variable2', value: '$variable3' },
{ key: 'variable3', value: 'key$variable$variable2' }
]
+ },
+ "file variables with expand_file_refs: true": {
+ variables: [
+ { key: 'file_var', value: 'secret content', file: true },
+ { key: 'variable1', value: 'var one' },
+ { key: 'variable2', value: 'var two $variable1 $file_var' }
+ ],
+ result: [
+ { key: 'file_var', value: 'secret content' },
+ { key: 'variable1', value: 'var one' },
+ { key: 'variable2', value: 'var two var one secret content' }
+ ]
+ },
+ "file variables with expand_file_refs: false": {
+ variables: [
+ { key: 'file_var', value: 'secret content', file: true },
+ { key: 'variable1', value: 'var one' },
+ { key: 'variable2', value: 'var two $variable1 $file_var' }
+ ],
+ expand_file_refs: false,
+ result: [
+ { key: 'file_var', value: 'secret content' },
+ { key: 'variable1', value: 'var one' },
+ { key: 'variable2', value: 'var two var one $file_var' }
+ ]
}
}
end
with_them do
let(:collection) { Gitlab::Ci::Variables::Collection.new(variables) }
- let(:options) { { keep_undefined: keep_undefined, expand_raw_refs: expand_raw_refs }.compact }
+ let(:options) do
+ { keep_undefined: keep_undefined,
+ expand_raw_refs: expand_raw_refs,
+ expand_file_refs: expand_file_refs }.compact
+ end
subject(:expanded_result) { collection.sort_and_expand_all(**options) }
@@ -585,43 +559,21 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
end
end
end
+ end
- context 'with the file_variable_is_referenced_in_another_variable logging' do
- let(:collection) do
- Gitlab::Ci::Variables::Collection.new
- .append(key: 'VAR1', value: 'test-1')
- .append(key: 'VAR2', value: '$VAR1')
- .append(key: 'VAR3', value: '$VAR1', raw: true)
- .append(key: 'FILEVAR4', value: 'file-test-4', file: true)
- .append(key: 'VAR5', value: '$FILEVAR4')
- .append(key: 'VAR6', value: '$FILEVAR4', raw: true)
- end
-
- subject(:sort_and_expand_all) { collection.sort_and_expand_all(project: project) }
-
- context 'when a project is not passed' do
- let(:project) {}
-
- it 'does not log anything' do
- expect(Gitlab::AppJsonLogger).not_to receive(:info)
-
- sort_and_expand_all
- end
- end
+ describe '#to_s' do
+ let(:variables) do
+ [
+ { key: 'VAR', value: 'value', public: true },
+ { key: 'VAR2', value: 'value2', public: false }
+ ]
+ end
- context 'when a project is passed' do
- let(:project) { create(:project) }
+ let(:errors) { 'circular variable reference detected' }
+ let(:collection) { Gitlab::Ci::Variables::Collection.new(variables, errors) }
- it 'logs file_variable_is_referenced_in_another_variable once for VAR5' do
- expect(Gitlab::AppJsonLogger).to receive(:info).with(
- event: 'file_variable_is_referenced_in_another_variable',
- project_id: project.id,
- variable: 'FILEVAR4'
- ).once
+ subject(:result) { collection.to_s }
- sort_and_expand_all
- end
- end
- end
+ it { is_expected.to eq("[\"VAR\", \"VAR2\"], @errors='circular variable reference detected'") }
end
end