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
Léo-Paul Géneau
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
...
@@ -477,96 +477,120 @@ module Ci
end
end
describe
'Variables'
do
describe
'Variables'
do
context
'when global variables are defined'
do
let
(
:config_processor
)
{
GitlabCiYamlProcessor
.
new
(
YAML
.
dump
(
config
),
path
)
}
it
'returns global variables'
do
variables
=
{
VAR1
:
'value1'
,
VAR2
:
'value2'
,
}
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
,
variables:
variables
,
before_script:
[
'pwd'
],
before_script:
[
'pwd'
],
rspec:
{
script:
'rspec'
}
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
end
end
context
'when job variables are defined'
do
context
'when job variables are defined'
do
context
'when syntax is correct'
do
let
(
:config
)
do
it
'returns job variables'
do
{
variables
=
{
before_script:
[
'pwd'
],
KEY1
:
'value1'
,
rspec:
{
script:
'rspec'
,
variables:
variables
}
SOME_KEY_2
:
'value2'
}
}
end
config
=
YAML
.
dump
(
context
'when also global variables are defined'
do
{
before_script:
[
'pwd'
],
rspec:
{
variables:
variables
,
script:
'rspec'
}
})
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
end
end
context
'when syntax is incorrect'
do
context
'when syntax is incorrect'
do
context
'when variables defined but invalid'
do
context
'when variables defined but invalid'
do
it
'raises error'
do
let
(
:variables
)
do
variables
=
[
:KEY1
,
'value1'
,
:KEY2
,
'value2'
]
[
:VAR1
,
'value1'
,
:VAR2
,
'value2'
]
end
config
=
YAML
.
dump
(
{
before_script:
[
'pwd'
],
rspec:
{
variables:
variables
,
script:
'rspec'
}
})
expect
{
GitlabCiYamlProcessor
.
new
(
config
,
path
)
}
it
'raises error'
do
expect
{
subject
}
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
/job: variables should be a map/
)
/job: variables should be a map/
)
end
end
end
end
context
'when variables key defined but value not specified'
do
context
'when variables key defined but value not specified'
do
it
'returns empty array'
do
let
(
:variables
)
do
config
=
YAML
.
dump
(
nil
{
before_script:
[
'pwd'
],
end
rspec:
{
variables:
nil
,
script:
'rspec'
}
})
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
it
'returns empty array'
do
##
##
# When variables config is empty, we assume this is a valid
# When variables config is empty, we assume this is a valid
# configuration, see issue #18775
# configuration, see issue #18775
#
#
expect
(
config_processor
.
job_variables
(
:rspec
)
)
expect
(
subject
).
to
be_an_instance_of
(
Array
)
.
to
be_an_instance_of
(
Array
).
and
be_empty
expect
(
subject
).
to
be_empty
end
end
end
end
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
let
(
:config
)
do
config
=
YAML
.
dump
(
{
{
before_script:
[
'pwd'
],
before_script:
[
'pwd'
],
rspec:
{
script:
'rspec'
}
rspec:
{
script:
'rspec'
}
})
}
end
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
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
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