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
4491bf28
Commit
4491bf28
authored
Jul 06, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move CI job config validations to new classes
parent
580c4e18
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
17 deletions
+59
-17
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+0
-2
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+1
-0
lib/gitlab/ci/config/node/jobs.rb
lib/gitlab/ci/config/node/jobs.rb
+15
-0
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+8
-1
spec/lib/gitlab/ci/config/node/global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+5
-2
spec/lib/gitlab/ci/config/node/jobs_spec.rb
spec/lib/gitlab/ci/config/node/jobs_spec.rb
+30
-12
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
4491bf28
...
...
@@ -71,8 +71,6 @@ module Ci
@ci_config
.
jobs
.
each
do
|
name
,
param
|
add_job
(
name
,
param
)
end
raise
ValidationError
,
"Please define at least one job"
if
@jobs
.
none?
end
def
add_job
(
name
,
job
)
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
4491bf28
...
...
@@ -24,6 +24,7 @@ module Gitlab
compose!
process_nodes!
@validator
.
validate
(
:processed
)
end
def
leaf?
...
...
lib/gitlab/ci/config/node/jobs.rb
View file @
4491bf28
...
...
@@ -10,12 +10,27 @@ module Gitlab
validations
do
validates
:config
,
type:
Hash
validate
:jobs_presence
,
on: :processed
def
jobs_presence
unless
relevant?
errors
.
add
(
:config
,
'should contain at least one visible job'
)
end
end
end
def
nodes
@config
end
def
relevant?
@nodes
.
values
.
any?
(
&
:relevant?
)
end
def
leaf?
false
end
private
def
create_node
(
key
,
essence
)
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
4491bf28
...
...
@@ -1061,7 +1061,14 @@ EOT
config
=
YAML
.
dump
({
before_script:
[
"bundle update"
]
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"Please define at least one job"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"jobs config should contain at least one visible job"
)
end
it
"returns errors if there are no visible jobs defined"
do
config
=
YAML
.
dump
({
before_script:
[
"bundle update"
],
'.hidden'
.
to_sym
=>
{}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"jobs config should contain at least one visible job"
)
end
it
"returns errors if job allow_failure parameter is not an boolean"
do
...
...
spec/lib/gitlab/ci/config/node/global_spec.rb
View file @
4491bf28
...
...
@@ -108,7 +108,10 @@ describe Gitlab::Ci::Config::Node::Global do
end
context
'when deprecated types key defined'
do
let
(
:hash
)
{
{
types:
[
'test'
,
'deploy'
]
}
}
let
(
:hash
)
do
{
types:
[
'test'
,
'deploy'
],
rspec:
{
script:
'rspec'
}
}
end
it
'returns array of types as stages'
do
expect
(
global
.
stages
).
to
eq
%w[test deploy]
...
...
@@ -174,7 +177,7 @@ describe Gitlab::Ci::Config::Node::Global do
# details.
#
context
'when entires specified but not defined'
do
let
(
:hash
)
{
{
variables:
nil
}
}
let
(
:hash
)
{
{
variables:
nil
,
rspec:
{
script:
'rspec'
}
}
}
before
{
global
.
process!
}
describe
'#variables'
do
...
...
spec/lib/gitlab/ci/config/node/jobs_spec.rb
View file @
4491bf28
...
...
@@ -4,17 +4,9 @@ describe Gitlab::Ci::Config::Node::Jobs do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
describe
'validations'
do
before
{
entry
.
process!
}
context
'when entry config value is correct'
do
let
(
:config
)
{
{
rspec:
{
script:
'rspec'
}
}
}
describe
'#value'
do
it
'returns key value'
do
expect
(
entry
.
value
).
to
eq
(
rspec:
{
script:
'rspec'
})
end
end
describe
'#valid?'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
...
...
@@ -23,15 +15,34 @@ describe Gitlab::Ci::Config::Node::Jobs do
end
context
'when entry value is not correct'
do
describe
'#errors'
do
context
'incorrect config value type'
do
let
(
:config
)
{
[
'incorrect'
]
}
describe
'#errors'
do
it
'saves errors'
do
it
'returns error about incorrect type'
do
expect
(
entry
.
errors
)
.
to
include
'jobs config should be a hash'
end
end
context
'when no visible jobs present'
do
let
(
:config
)
{
{
'.hidden'
.
to_sym
=>
{}
}
}
context
'when not processed'
do
it
'is valid'
do
expect
(
entry
.
errors
).
to
be_empty
end
end
context
'when processed'
do
before
{
entry
.
process!
}
it
'returns error about no visible jobs defined'
do
expect
(
entry
.
errors
)
.
to
include
'jobs config should contain at least one visible job'
end
end
end
end
end
end
...
...
@@ -45,6 +56,13 @@ describe Gitlab::Ci::Config::Node::Jobs do
'.hidden'
.
to_sym
=>
{}
}
end
describe
'#value'
do
it
'returns key value'
do
expect
(
entry
.
value
).
to
eq
(
rspec:
{
script:
'rspec'
},
spinach:
{
script:
'spinach'
})
end
end
describe
'#descendants'
do
it
'creates valid descendant nodes'
do
expect
(
entry
.
descendants
.
count
).
to
eq
3
...
...
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