Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d38b8b80
Commit
d38b8b80
authored
Mar 03, 2021
by
Pedro Pombeiro
Committed by
Kamil Trzciński
Mar 03, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add :raw attribute to Collection::Item
parent
1a0afd17
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
1 deletion
+75
-1
lib/gitlab/ci/variables/collection/item.rb
lib/gitlab/ci/variables/collection/item.rb
+6
-1
spec/lib/gitlab/ci/variables/collection/item_spec.rb
spec/lib/gitlab/ci/variables/collection/item_spec.rb
+38
-0
spec/lib/gitlab/ci/variables/collection/sort_spec.rb
spec/lib/gitlab/ci/variables/collection/sort_spec.rb
+31
-0
No files found.
lib/gitlab/ci/variables/collection/item.rb
View file @
d38b8b80
...
...
@@ -7,11 +7,14 @@ module Gitlab
class
Item
include
Gitlab
::
Utils
::
StrongMemoize
def
initialize
(
key
:,
value
:,
public:
true
,
file:
false
,
masked:
false
)
attr_reader
:raw
def
initialize
(
key
:,
value
:,
public:
true
,
file:
false
,
masked:
false
,
raw:
false
)
raise
ArgumentError
,
"`
#{
key
}
` must be of type String or nil value, while it was:
#{
value
.
class
}
"
unless
value
.
is_a?
(
String
)
||
value
.
nil?
@variable
=
{
key:
key
,
value:
value
,
public:
public
,
file:
file
,
masked:
masked
}
@raw
=
raw
end
def
value
...
...
@@ -28,6 +31,8 @@ module Gitlab
def
depends_on
strong_memoize
(
:depends_on
)
do
next
if
raw
next
unless
ExpandVariables
.
possible_var_reference?
(
value
)
value
.
scan
(
ExpandVariables
::
VARIABLES_REGEXP
).
map
(
&
:first
)
...
...
spec/lib/gitlab/ci/variables/collection/item_spec.rb
View file @
d38b8b80
...
...
@@ -92,6 +92,10 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Item do
variable:
{
key:
'VAR'
,
value:
'something_${VAR2}_$VAR3'
},
expected_depends_on:
%w(VAR2 VAR3)
},
"complex expansion in raw variable"
:
{
variable:
{
key:
'VAR'
,
value:
'something_${VAR2}_$VAR3'
,
raw:
true
},
expected_depends_on:
nil
},
"complex expansions for Windows"
:
{
variable:
{
key:
'variable3'
,
value:
'key%variable%%variable2%'
},
expected_depends_on:
%w(variable variable2)
...
...
@@ -156,6 +160,26 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Item do
end
end
describe
'#raw'
do
it
'returns false when :raw is not specified'
do
item
=
described_class
.
new
(
**
variable
)
expect
(
item
.
raw
).
to
eq
false
end
context
'when :raw is specified as true'
do
let
(
:variable
)
do
{
key:
variable_key
,
value:
variable_value
,
public:
true
,
masked:
false
,
raw:
true
}
end
it
'returns true'
do
item
=
described_class
.
new
(
**
variable
)
expect
(
item
.
raw
).
to
eq
true
end
end
end
describe
'#to_runner_variable'
do
context
'when variable is not a file-related'
do
it
'returns a runner-compatible hash representation'
do
...
...
@@ -185,5 +209,19 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Item do
expect
(
runner_variable
.
depends_on
).
to
eq
(
%w(CI_VAR_2 CI_VAR_3)
)
end
end
context
'when assigned the raw attribute'
do
it
'retains a true raw attribute'
do
runner_variable
=
described_class
.
new
(
key:
'CI_VAR'
,
value:
'123'
,
raw:
true
)
expect
(
runner_variable
).
to
eq
(
key:
'CI_VAR'
,
value:
'123'
,
public:
true
,
masked:
false
,
raw:
true
)
end
it
'does not retain a false raw attribute'
do
runner_variable
=
described_class
.
new
(
key:
'CI_VAR'
,
value:
'123'
,
raw:
false
)
expect
(
runner_variable
).
to
eq
(
key:
'CI_VAR'
,
value:
'123'
,
public:
true
,
masked:
false
)
end
end
end
end
spec/lib/gitlab/ci/variables/collection/sort_spec.rb
View file @
d38b8b80
...
...
@@ -76,6 +76,13 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sort do
{
key:
'variable2'
,
value:
'$variable3'
},
{
key:
'variable3'
,
value:
'key$variable$variable2'
}
]
},
"array with raw variable"
:
{
variables:
[
{
key:
'variable'
,
value:
'$variable2'
},
{
key:
'variable2'
,
value:
'$variable3'
},
{
key:
'variable3'
,
value:
'key$variable$variable2'
,
raw:
true
}
]
}
}
end
...
...
@@ -128,6 +135,14 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sort do
{
key:
'variable3'
,
value:
'key$variable$variable2'
}
],
validation_result:
'circular variable reference detected: ["variable", "variable2", "variable3"]'
},
"array with raw variable"
:
{
variables:
[
{
key:
'variable'
,
value:
'$variable2'
},
{
key:
'variable2'
,
value:
'$variable3'
},
{
key:
'variable3'
,
value:
'key$variable$variable2'
,
raw:
true
}
],
validation_result:
nil
}
}
end
...
...
@@ -271,6 +286,22 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sort do
{
key:
'variable'
,
value:
'$variable2'
}
],
result:
%w[variable2 variable3 variable]
},
"raw variable does not get resolved"
:
{
variables:
[
{
key:
'variable'
,
value:
'$variable2'
},
{
key:
'variable2'
,
value:
'$variable3'
},
{
key:
'variable3'
,
value:
'key$variable$variable2'
,
raw:
true
}
],
result:
%w[variable3 variable2 variable]
},
"variable containing escaped variable reference"
:
{
variables:
[
{
key:
'variable_c'
,
value:
'$variable_b'
},
{
key:
'variable_b'
,
value:
'$$variable_a'
},
{
key:
'variable_a'
,
value:
'value'
}
],
result:
%w[variable_a variable_b variable_c]
}
}
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment