BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d9142f2c
Commit
d9142f2c
authored
Jul 08, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CI config known stage validation for job stage
parent
1ac62de2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
11 deletions
+56
-11
stage.rb
lib/gitlab/ci/config/node/stage.rb
+13
-0
stage_spec.rb
spec/lib/gitlab/ci/config/node/stage_spec.rb
+43
-11
No files found.
lib/gitlab/ci/config/node/stage.rb
View file @
d9142f2c
...
@@ -11,6 +11,19 @@ module Gitlab
...
@@ -11,6 +11,19 @@ module Gitlab
validations
do
validations
do
validates
:config
,
key:
true
validates
:config
,
key:
true
validates
:global
,
required_attribute:
true
validates
:global
,
required_attribute:
true
validate
:known_stage
,
on: :after
def
known_stage
unless
known?
stages_list
=
global
.
stages
.
join
(
', '
)
errors
.
add
(
:config
,
"should be one of defined stages (
#{
stages_list
}
)"
)
end
end
end
def
known?
@global
.
stages
.
include?
(
@config
)
end
end
def
self
.
default
def
self
.
default
...
...
spec/lib/gitlab/ci/config/node/stage_spec.rb
View file @
d9142f2c
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Stage
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Stage
do
let
(
:
entry
)
{
described_class
.
new
(
config
,
global:
global
)
}
let
(
:
stage
)
{
described_class
.
new
(
config
,
global:
global
)
}
let
(
:global
)
{
spy
(
'Global'
)
}
let
(
:global
)
{
spy
(
'Global'
)
}
describe
'validations'
do
describe
'validations'
do
context
'when
entry
config value is correct'
do
context
'when
stage
config value is correct'
do
let
(
:config
)
{
:build
}
let
(
:config
)
{
:build
}
describe
'#value'
do
describe
'#value'
do
it
'returns a stage key'
do
it
'returns a stage key'
do
expect
(
entry
.
value
).
to
eq
config
expect
(
stage
.
value
).
to
eq
config
end
end
end
end
describe
'#valid?'
do
describe
'#valid?'
do
it
'is valid'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
expect
(
stage
).
to
be_valid
end
end
end
end
end
end
context
'when
entry
config is incorrect'
do
context
'when
stage
config is incorrect'
do
describe
'#errors'
do
describe
'#errors'
do
context
'when reference to global node is not set'
do
context
'when reference to global node is not set'
do
let
(
:
entry
)
{
described_class
.
new
(
config
)
}
let
(
:
stage
)
{
described_class
.
new
(
config
)
}
it
'raises error'
do
it
'raises error'
do
expect
{
entry
}.
to
raise_error
(
expect
{
stage
}.
to
raise_error
(
Gitlab
::
Ci
::
Config
::
Node
::
Entry
::
InvalidError
,
Gitlab
::
Ci
::
Config
::
Node
::
Entry
::
InvalidError
,
/Entry needs global attribute set internally./
/Entry needs global attribute set internally./
)
)
...
@@ -38,21 +38,53 @@ describe Gitlab::Ci::Config::Node::Stage do
...
@@ -38,21 +38,53 @@ describe Gitlab::Ci::Config::Node::Stage do
let
(
:config
)
{
{
test:
true
}
}
let
(
:config
)
{
{
test:
true
}
}
it
'reports errors about wrong type'
do
it
'reports errors about wrong type'
do
expect
(
entry
.
errors
)
expect
(
stage
.
errors
)
.
to
include
'stage config should be a string or symbol'
.
to
include
'stage config should be a string or symbol'
end
end
end
end
context
'when stage is not present in global configuration'
do
context
'when stage is not present in global configuration'
do
pending
'reports error about missing stage'
do
let
(
:config
)
{
:unknown
}
expect
(
entry
.
errors
)
.
to
include
'stage config should be one of test, stage'
before
do
allow
(
global
)
.
to
receive
(
:stages
).
and_return
([
:test
,
:deploy
])
end
it
'reports error about missing stage'
do
stage
.
validate!
expect
(
stage
.
errors
)
.
to
include
'stage config should be one of '
\
'defined stages (test, deploy)'
end
end
end
end
end
end
end
end
end
end
describe
'#known?'
do
before
do
allow
(
global
).
to
receive
(
:stages
).
and_return
([
:test
,
:deploy
])
end
context
'when stage is not known'
do
let
(
:config
)
{
:unknown
}
it
'returns false'
do
expect
(
stage
.
known?
).
to
be
false
end
end
context
'when stage is known'
do
let
(
:config
)
{
:test
}
it
'returns false'
do
expect
(
stage
.
known?
).
to
be
true
end
end
end
describe
'.default'
do
describe
'.default'
do
it
'returns default stage'
do
it
'returns default stage'
do
expect
(
described_class
.
default
).
to
eq
:test
expect
(
described_class
.
default
).
to
eq
:test
...
...
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