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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
cf3e3eff
Commit
cf3e3eff
authored
Apr 16, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor refactoring in code related to job variables
parent
a6260b1e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
24 deletions
+25
-24
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+1
-5
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+24
-19
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
cf3e3eff
...
@@ -45,11 +45,7 @@ module Ci
...
@@ -45,11 +45,7 @@ module Ci
end
end
def
job_variables
(
name
)
def
job_variables
(
name
)
if
job
=
@jobs
[
name
.
to_sym
]
@jobs
[
name
.
to_sym
].
try
(
:fetch
,
:variables
,
[])
||
[]
job
[
:variables
]
||
[]
else
[]
end
end
end
private
private
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
cf3e3eff
...
@@ -345,50 +345,55 @@ module Ci
...
@@ -345,50 +345,55 @@ module Ci
end
end
end
end
describe
"Variables"
do
describe
'Variables'
do
context
'when global variables are defined'
do
context
'when global variables are defined'
do
it
'returns variables'
do
it
'returns
global
variables'
do
variables
=
{
variables
=
{
var1:
"value1"
,
VAR1
:
'value1'
,
var2:
"value2"
,
VAR2
:
'value2'
,
}
}
config
=
YAML
.
dump
({
config
=
YAML
.
dump
({
variables:
variables
,
variables:
variables
,
before_script:
[
"pwd"
],
before_script:
[
'pwd'
],
rspec:
{
script:
"rspec"
}
rspec:
{
script:
'rspec'
}
})
})
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
expect
(
config_processor
.
global_variables
).
to
eq
(
variables
)
expect
(
config_processor
.
global_variables
).
to
eq
(
variables
)
end
end
end
end
context
'when job variables are defined'
do
context
'when job variables are defined'
do
let
(
:job_variables
)
{
{
KEY1
:
'value1'
,
SOME_KEY_2
:
'value2'
}
}
it
'returns job variables'
do
let
(
:yaml_config
)
do
variables
=
{
YAML
.
dump
(
KEY1
:
'value1'
,
SOME_KEY_2
:
'value2'
}
config
=
YAML
.
dump
(
{
before_script:
[
'pwd'
],
{
before_script:
[
'pwd'
],
rspec:
{
rspec:
{
variables:
job_
variables
,
variables:
variables
,
script:
'rspec'
}
script:
'rspec'
}
})
})
end
it
'returns job variables'
do
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
config
=
GitlabCiYamlProcessor
.
new
(
yaml_config
,
path
)
expect
(
config
.
job_variables
(
:rspec
)).
to
eq
job_
variables
expect
(
config
_processor
.
job_variables
(
:rspec
)).
to
eq
variables
end
end
end
end
context
'when job variables are not defined'
do
context
'when job variables are not defined'
do
it
'returns empty array'
do
it
'returns empty array'
do
config
=
YAML
.
dump
({
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
before_script:
[
'pwd'
],
rspec:
{
script:
"rspec"
}
rspec:
{
script:
'rspec'
}
})
})
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
expect
(
config_processor
.
job_variables
(
:rspec
)).
to
eq
[]
expect
(
config_processor
.
job_variables
(
:rspec
)).
to
eq
[]
end
end
end
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