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
585e6a99
Commit
585e6a99
authored
Mar 21, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for chain element that populates a pipeline
parent
e79ebabb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
23 deletions
+126
-23
lib/gitlab/ci/pipeline/chain/populate.rb
lib/gitlab/ci/pipeline/chain/populate.rb
+7
-1
spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
+13
-22
spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
+106
-0
No files found.
lib/gitlab/ci/pipeline/chain/populate.rb
View file @
585e6a99
...
...
@@ -3,6 +3,8 @@ module Gitlab
module
Pipeline
module
Chain
class
Populate
<
Chain
::
Base
include
Chain
::
Helpers
PopulateError
=
Class
.
new
(
StandardError
)
def
perform!
...
...
@@ -19,11 +21,15 @@ module Gitlab
pipeline
.
stages
<<
seed
.
to_resource
end
if
pipeline
.
invalid?
error
(
'Failed to build the pipeline!'
)
end
raise
Populate
::
PopulateError
if
pipeline
.
persisted?
end
def
break?
pipeline
.
persiste
d?
pipeline
.
invali
d?
end
end
end
...
...
spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
View file @
585e6a99
...
...
@@ -5,23 +5,23 @@ describe Gitlab::Ci::Pipeline::Chain::Create do
set
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline
)
do
build
(
:ci_pipeline_with_one_job
,
project:
project
,
ref:
'master'
)
build
(
:ci_empty_pipeline
,
project:
project
,
ref:
'master'
)
end
let
(
:command
)
do
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
project:
project
,
current_user:
user
,
seeds_block:
nil
)
project:
project
,
current_user:
user
)
end
let
(
:step
)
{
described_class
.
new
(
pipeline
,
command
)
}
before
do
step
.
perform!
end
context
'when pipeline is ready to be saved'
do
before
do
pipeline
.
stages
.
build
(
name:
'test'
,
project:
project
)
step
.
perform!
end
it
'saves a pipeline'
do
expect
(
pipeline
).
to
be_persisted
end
...
...
@@ -32,6 +32,7 @@ describe Gitlab::Ci::Pipeline::Chain::Create do
it
'creates stages'
do
expect
(
pipeline
.
reload
.
stages
).
to
be_one
expect
(
pipeline
.
stages
.
first
).
to
be_persisted
end
end
...
...
@@ -40,6 +41,10 @@ describe Gitlab::Ci::Pipeline::Chain::Create do
build
(
:ci_pipeline
,
project:
project
,
ref:
nil
)
end
before
do
step
.
perform!
end
it
'breaks the chain'
do
expect
(
step
.
break?
).
to
be
true
end
...
...
@@ -49,18 +54,4 @@ describe Gitlab::Ci::Pipeline::Chain::Create do
.
to
include
/Failed to persist the pipeline/
end
end
context
'when there is a seed block present'
do
let
(
:seeds
)
{
spy
(
'pipeline seeds'
)
}
let
(
:command
)
do
double
(
'command'
,
project:
project
,
current_user:
user
,
seeds_block:
seeds
)
end
it
'executes the block'
do
expect
(
seeds
).
to
have_received
(
:call
).
with
(
pipeline
)
end
end
end
spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
0 → 100644
View file @
585e6a99
require
'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Populate
do
set
(
:project
)
{
create
(
:project
)
}
set
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline
)
do
build
(
:ci_pipeline_with_one_job
,
project:
project
,
ref:
'master'
)
end
let
(
:command
)
do
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
project:
project
,
current_user:
user
,
seeds_block:
nil
)
end
let
(
:step
)
{
described_class
.
new
(
pipeline
,
command
)
}
context
'when pipeline doesn not have seeds block'
do
before
do
step
.
perform!
end
it
'does not persist the pipeline'
do
expect
(
pipeline
).
not_to
be_persisted
end
it
'does not break the chain'
do
expect
(
step
.
break?
).
to
be
false
end
it
'populates pipeline with stages'
do
expect
(
pipeline
.
stages
).
to
be_one
expect
(
pipeline
.
stages
.
first
).
not_to
be_persisted
end
it
'populates pipeline with builds'
do
expect
(
pipeline
.
stages
.
first
.
builds
).
to
be_one
expect
(
pipeline
.
stages
.
first
.
builds
.
first
).
not_to
be_persisted
end
end
context
'when pipeline has validation errors'
do
let
(
:pipeline
)
do
build
(
:ci_pipeline
,
project:
project
,
ref:
nil
)
end
before
do
step
.
perform!
end
it
'breaks the chain'
do
expect
(
step
.
break?
).
to
be
true
end
it
'appends validation error'
do
expect
(
pipeline
.
errors
.
to_a
)
.
to
include
'Failed to build the pipeline!'
end
end
context
'when there is a seed blocks present'
do
let
(
:command
)
do
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
project:
project
,
current_user:
user
,
seeds_block:
seeds_block
)
end
context
'when seeds block builds some resources'
do
let
(
:seeds_block
)
do
->
(
pipeline
)
{
pipeline
.
variables
.
build
(
key:
'VAR'
,
value:
'123'
)
}
end
it
'populates pipeline with resources described in the seeds block'
do
step
.
perform!
expect
(
pipeline
).
not_to
be_persisted
expect
(
pipeline
.
variables
).
not_to
be_empty
expect
(
pipeline
.
variables
.
first
).
not_to
be_persisted
expect
(
pipeline
.
variables
.
first
.
key
).
to
eq
'VAR'
expect
(
pipeline
.
variables
.
first
.
value
).
to
eq
'123'
end
end
context
'when seeds block tries to persist some resources'
do
let
(
:seeds_block
)
do
->
(
pipeline
)
{
pipeline
.
variables
.
create!
(
key:
'VAR'
,
value:
'123'
)
}
end
it
'raises exception'
do
expect
{
step
.
perform!
}.
to
raise_error
(
ActiveRecord
::
RecordNotSaved
)
end
end
end
context
'when pipeline gets persisted during the process'
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
it
'raises error'
do
expect
{
step
.
perform!
}.
to
raise_error
(
described_class
::
PopulateError
)
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