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
bc2348f2
Commit
bc2348f2
authored
Jun 22, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return default config value when entry is undefined
parent
05ce8a11
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
74 additions
and
51 deletions
+74
-51
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+3
-3
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+3
-0
lib/gitlab/ci/config/node/factory.rb
lib/gitlab/ci/config/node/factory.rb
+5
-4
lib/gitlab/ci/config/node/global.rb
lib/gitlab/ci/config/node/global.rb
+5
-5
lib/gitlab/ci/config/node/undefined.rb
lib/gitlab/ci/config/node/undefined.rb
+11
-7
lib/gitlab/ci/config/node/variables.rb
lib/gitlab/ci/config/node/variables.rb
+5
-1
spec/lib/gitlab/ci/config/node/configurable_spec.rb
spec/lib/gitlab/ci/config/node/configurable_spec.rb
+1
-1
spec/lib/gitlab/ci/config/node/undefined_spec.rb
spec/lib/gitlab/ci/config/node/undefined_spec.rb
+18
-7
spec/lib/gitlab/ci/config_spec.rb
spec/lib/gitlab/ci/config_spec.rb
+23
-23
No files found.
lib/gitlab/ci/config/node/configurable.rb
View file @
bc2348f2
...
@@ -33,12 +33,12 @@ module Gitlab
...
@@ -33,12 +33,12 @@ module Gitlab
class_methods
do
class_methods
do
def
nodes
def
nodes
Hash
[
@
allowed_
nodes
.
map
{
|
key
,
factory
|
[
key
,
factory
.
dup
]
}]
Hash
[
@nodes
.
map
{
|
key
,
factory
|
[
key
,
factory
.
dup
]
}]
end
end
private
private
def
allow_
node
(
symbol
,
entry_class
,
metadata
)
def
node
(
symbol
,
entry_class
,
metadata
)
factory
=
Node
::
Factory
.
new
(
entry_class
)
factory
=
Node
::
Factory
.
new
(
entry_class
)
.
with
(
description:
metadata
[
:description
])
.
with
(
description:
metadata
[
:description
])
...
@@ -47,7 +47,7 @@ module Gitlab
...
@@ -47,7 +47,7 @@ module Gitlab
@nodes
[
symbol
].
try
(
:value
)
@nodes
[
symbol
].
try
(
:value
)
end
end
(
@
allowed_
nodes
||=
{}).
merge!
(
symbol
=>
factory
)
(
@nodes
||=
{}).
merge!
(
symbol
=>
factory
)
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
bc2348f2
...
@@ -52,6 +52,9 @@ module Gitlab
...
@@ -52,6 +52,9 @@ module Gitlab
@config
@config
end
end
def
self
.
default
end
def
self
.
nodes
def
self
.
nodes
{}
{}
end
end
...
...
lib/gitlab/ci/config/node/factory.rb
View file @
bc2348f2
...
@@ -8,8 +8,8 @@ module Gitlab
...
@@ -8,8 +8,8 @@ module Gitlab
class
Factory
class
Factory
class
InvalidFactory
<
StandardError
;
end
class
InvalidFactory
<
StandardError
;
end
def
initialize
(
entry_class
)
def
initialize
(
node
)
@
entry_class
=
entry_class
@
node
=
node
@attributes
=
{}
@attributes
=
{}
end
end
...
@@ -19,14 +19,15 @@ module Gitlab
...
@@ -19,14 +19,15 @@ module Gitlab
end
end
def
undefine!
def
undefine!
@entry_class
=
Node
::
Undefined
@attributes
[
:value
]
=
@node
.
dup
@node
=
Node
::
Undefined
self
self
end
end
def
create!
def
create!
raise
InvalidFactory
unless
@attributes
.
has_key?
(
:value
)
raise
InvalidFactory
unless
@attributes
.
has_key?
(
:value
)
@
entry_class
.
new
(
@attributes
[
:value
]).
tap
do
|
entry
|
@
node
.
new
(
@attributes
[
:value
]).
tap
do
|
entry
|
entry
.
description
=
@attributes
[
:description
]
entry
.
description
=
@attributes
[
:description
]
entry
.
key
=
@attributes
[
:key
]
entry
.
key
=
@attributes
[
:key
]
end
end
...
...
lib/gitlab/ci/config/node/global.rb
View file @
bc2348f2
...
@@ -9,19 +9,19 @@ module Gitlab
...
@@ -9,19 +9,19 @@ module Gitlab
class
Global
<
Entry
class
Global
<
Entry
include
Configurable
include
Configurable
allow_
node
:before_script
,
Script
,
node
:before_script
,
Script
,
description:
'Script that will be executed before each job.'
description:
'Script that will be executed before each job.'
allow_
node
:image
,
Image
,
node
:image
,
Image
,
description:
'Docker image that will be used to execute jobs.'
description:
'Docker image that will be used to execute jobs.'
allow_
node
:services
,
Services
,
node
:services
,
Services
,
description:
'Docker images that will be linked to the container.'
description:
'Docker images that will be linked to the container.'
allow_
node
:after_script
,
Script
,
node
:after_script
,
Script
,
description:
'Script that will be executed after each job.'
description:
'Script that will be executed after each job.'
allow_
node
:variables
,
Variables
,
node
:variables
,
Variables
,
description:
'Environment variables that will be used.'
description:
'Environment variables that will be used.'
end
end
end
end
...
...
lib/gitlab/ci/config/node/undefined.rb
View file @
bc2348f2
...
@@ -3,17 +3,21 @@ module Gitlab
...
@@ -3,17 +3,21 @@ module Gitlab
class
Config
class
Config
module
Node
module
Node
##
##
# This class represents a configuration entry that is not defined
# This class represents an undefined entry node.
# in configuration file.
#
#
# This implements a Null Object pattern.
# It takes original entry class as configuration and returns default
# value of original entry as self value.
#
#
# It can be initialized using a default value of entry that is not
# present in configuration.
#
#
class
Undefined
<
Entry
class
Undefined
<
Entry
def
method_missing
(
*
)
include
Validatable
nil
validations
do
validates
:config
,
type:
Class
end
def
value
@config
.
default
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/variables.rb
View file @
bc2348f2
...
@@ -13,7 +13,11 @@ module Gitlab
...
@@ -13,7 +13,11 @@ module Gitlab
end
end
def
value
def
value
@config
||
{}
@config
||
self
.
class
.
default
end
def
self
.
default
{}
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/configurable_spec.rb
View file @
bc2348f2
...
@@ -10,7 +10,7 @@ describe Gitlab::Ci::Config::Node::Configurable do
...
@@ -10,7 +10,7 @@ describe Gitlab::Ci::Config::Node::Configurable do
describe
'configured nodes'
do
describe
'configured nodes'
do
before
do
before
do
node
.
class_eval
do
node
.
class_eval
do
allow_
node
:object
,
Object
,
description:
'test object'
node
:object
,
Object
,
description:
'test object'
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/undefined_spec.rb
View file @
bc2348f2
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Undefined
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Undefined
do
let
(
:entry
)
{
described_class
.
new
(
'some value'
)
}
let
(
:undefined
)
{
described_class
.
new
(
entry
)
}
let
(
:entry
)
{
Class
.
new
}
describe
'#leaf?'
do
describe
'#leaf?'
do
it
'is leaf node'
do
it
'is leaf node'
do
expect
(
entry
).
to
be_leaf
expect
(
undefined
).
to
be_leaf
end
end
end
end
describe
'#any_method'
do
describe
'#valid?'
do
it
'responds with nil'
do
it
'is always valid'
do
expect
(
entry
.
any_method
).
to
be
nil
expect
(
undefined
).
to
be_valid
end
end
describe
'#errors'
do
it
'is does not contain errors'
do
expect
(
undefined
.
errors
).
to
be_empty
end
end
end
end
describe
'#value'
do
describe
'#value'
do
it
'returns configured value'
do
before
do
expect
(
entry
.
value
).
to
eq
'some value'
allow
(
entry
).
to
receive
(
:default
).
and_return
(
'some value'
)
end
it
'returns default value for entry that is undefined'
do
expect
(
undefined
.
value
).
to
eq
'some value'
end
end
end
end
end
end
spec/lib/gitlab/ci/config_spec.rb
View file @
bc2348f2
...
@@ -40,38 +40,38 @@ describe Gitlab::Ci::Config do
...
@@ -40,38 +40,38 @@ describe Gitlab::Ci::Config do
end
end
end
end
end
end
end
context
'when config is invalid'
do
context
'when config is invalid'
do
context
'when yml is incorrect'
do
context
'when yml is incorrect'
do
let
(
:yml
)
{
'// invalid'
}
let
(
:yml
)
{
'// invalid'
}
describe
'.new'
do
describe
'.new'
do
it
'raises error'
do
it
'raises error'
do
expect
{
config
}.
to
raise_error
(
expect
{
config
}.
to
raise_error
(
Gitlab
::
Ci
::
Config
::
Loader
::
FormatError
,
Gitlab
::
Ci
::
Config
::
Loader
::
FormatError
,
/Invalid configuration format/
/Invalid configuration format/
)
)
end
end
end
end
end
end
context
'when config logic is incorrect'
do
context
'when config logic is incorrect'
do
let
(
:yml
)
{
'before_script: "ls"'
}
let
(
:yml
)
{
'before_script: "ls"'
}
describe
'#valid?'
do
describe
'#valid?'
do
it
'is not valid'
do
it
'is not valid'
do
expect
(
config
).
not_to
be_valid
expect
(
config
).
not_to
be_valid
end
end
it
'has errors'
do
it
'has errors'
do
expect
(
config
.
errors
).
not_to
be_empty
expect
(
config
.
errors
).
not_to
be_empty
end
end
end
end
describe
'#errors'
do
describe
'#errors'
do
it
'returns an array of strings'
do
it
'returns an array of strings'
do
expect
(
config
.
errors
).
to
all
(
be_an_instance_of
(
String
))
expect
(
config
.
errors
).
to
all
(
be_an_instance_of
(
String
))
end
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