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
22c2814b
Commit
22c2814b
authored
Jul 17, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor gitlab_ci_yaml_processor variables tests
parent
aafd4349
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
52 deletions
+76
-52
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+76
-52
No files found.
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
22c2814b
...
...
@@ -477,96 +477,120 @@ module Ci
end
describe
'Variables'
do
context
'when global variables are defined'
do
it
'returns global variables'
do
variables
=
{
VAR1
:
'value1'
,
VAR2
:
'value2'
,
}
let
(
:config_processor
)
{
GitlabCiYamlProcessor
.
new
(
YAML
.
dump
(
config
),
path
)
}
config
=
YAML
.
dump
({
subject
{
config_processor
.
builds
.
first
[
:yaml_variables
]
}
context
'when global variables are defined'
do
let
(
:variables
)
do
{
VAR1
:
'value1'
,
VAR2
:
'value2'
}
end
let
(
:config
)
do
{
variables:
variables
,
before_script:
[
'pwd'
],
rspec:
{
script:
'rspec'
}
})
}
end
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
it
'returns global variables'
do
expect
(
subject
).
to
contain_exactly
(
{
key: :VAR1
,
value:
'value1'
,
public:
true
},
{
key: :VAR2
,
value:
'value2'
,
public:
true
}
)
end
end
expect
(
config_processor
.
global_variables
).
to
eq
(
variables
)
context
'when job and global variables are defined'
do
let
(
:global_variables
)
do
{
VAR1
:
'global1'
,
VAR3
:
'global3'
}
end
let
(
:job_variables
)
do
{
VAR1
:
'value1'
,
VAR2
:
'value2'
}
end
let
(
:config
)
do
{
before_script:
[
'pwd'
],
variables:
global_variables
,
rspec:
{
script:
'rspec'
,
variables:
job_variables
}
}
end
it
'returns all unique variables'
do
expect
(
subject
).
to
contain_exactly
(
{
key: :VAR3
,
value:
'global3'
,
public:
true
},
{
key: :VAR1
,
value:
'value1'
,
public:
true
},
{
key: :VAR2
,
value:
'value2'
,
public:
true
}
)
end
end
context
'when job variables are defined'
do
context
'when syntax is correct'
do
it
'returns job variables'
do
variables
=
{
KEY1
:
'value1'
,
SOME_KEY_2
:
'value2'
let
(
:config
)
do
{
before_script:
[
'pwd'
],
rspec:
{
script:
'rspec'
,
variables:
variables
}
}
end
config
=
YAML
.
dump
(
{
before_script:
[
'pwd'
],
rspec:
{
variables:
variables
,
script:
'rspec'
}
})
context
'when also global variables are defined'
do
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
expect
(
config_processor
.
job_variables
(
:rspec
)).
to
eq
variables
context
'when syntax is correct'
do
let
(
:variables
)
do
{
VAR1
:
'value1'
,
VAR2
:
'value2'
}
end
it
'returns job variables'
do
expect
(
subject
).
to
contain_exactly
(
{
key: :VAR1
,
value:
'value1'
,
public:
true
},
{
key: :VAR2
,
value:
'value2'
,
public:
true
}
)
end
end
context
'when syntax is incorrect'
do
context
'when variables defined but invalid'
do
it
'raises error'
do
variables
=
[
:KEY1
,
'value1'
,
:KEY2
,
'value2'
]
config
=
YAML
.
dump
(
{
before_script:
[
'pwd'
],
rspec:
{
variables:
variables
,
script:
'rspec'
}
})
let
(
:variables
)
do
[
:VAR1
,
'value1'
,
:VAR2
,
'value2'
]
end
expect
{
GitlabCiYamlProcessor
.
new
(
config
,
path
)
}
it
'raises error'
do
expect
{
subject
}
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
/job: variables should be a map/
)
end
end
context
'when variables key defined but value not specified'
do
it
'returns empty array'
do
config
=
YAML
.
dump
(
{
before_script:
[
'pwd'
],
rspec:
{
variables:
nil
,
script:
'rspec'
}
})
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
let
(
:variables
)
do
nil
end
it
'returns empty array'
do
##
# When variables config is empty, we assume this is a valid
# configuration, see issue #18775
#
expect
(
config_processor
.
job_variables
(
:rspec
)
)
.
to
be_an_instance_of
(
Array
).
and
be_empty
expect
(
subject
).
to
be_an_instance_of
(
Array
)
expect
(
subject
).
to
be_empty
end
end
end
end
context
'when job variables are not defined'
do
it
'returns empty array'
do
config
=
YAML
.
dump
(
{
let
(
:config
)
do
{
before_script:
[
'pwd'
],
rspec:
{
script:
'rspec'
}
})
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
}
end
expect
(
config_processor
.
job_variables
(
:rspec
)).
to
eq
[]
it
'returns empty array'
do
expect
(
subject
).
to
be_an_instance_of
(
Array
)
expect
(
subject
).
to
be_empty
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