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
6d451113
Commit
6d451113
authored
Sep 28, 2018
by
Shinya Maeda
Committed by
Alessio Caiazza
Oct 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec for ProcessBuildService
parent
97c556bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
171 additions
and
28 deletions
+171
-28
spec/services/ci/process_build_service_spec.rb
spec/services/ci/process_build_service_spec.rb
+171
-28
No files found.
spec/services/ci/process_build_service_spec.rb
View file @
6d451113
...
@@ -5,62 +5,205 @@ describe Ci::ProcessBuildService, '#execute' do
...
@@ -5,62 +5,205 @@ describe Ci::ProcessBuildService, '#execute' do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
subject
{
described_class
.
new
(
project
,
user
).
execute
(
build
)
}
subject
{
described_class
.
new
(
project
,
user
).
execute
(
build
,
current_status
)
}
before
do
before
do
project
.
add_maintainer
(
user
)
project
.
add_maintainer
(
user
)
end
end
context
'when build is schedulable'
do
shared_examples_for
'Enqueuing properly'
do
|
valid_statuses_for_when
|
let
(
:build
)
{
create
(
:ci_build
,
:created
,
:schedulable
,
user:
user
,
project:
project
)
}
valid_statuses_for_when
.
each
do
|
status_for_prior_stages
|
context
"when status for prior stages is
#{
status_for_prior_stages
}
"
do
let
(
:current_status
)
{
status_for_prior_stages
}
context
'when ci_enable_scheduled_build feature flag is enabled'
do
%w[created skipped manual scheduled]
.
each
do
|
status
|
before
do
context
"when build status is
#{
status
}
"
do
stub_feature_flags
(
ci_enable_scheduled_build:
true
)
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
when:
when_option
,
user:
user
,
project:
project
)
}
it
'enqueues the build'
do
expect
{
subject
}.
to
change
{
build
.
status
}.
to
(
'pending'
)
end
end
end
%w[pending running success failed canceled]
.
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
when:
when_option
,
user:
user
,
project:
project
)
}
it
'does not change the build status'
do
expect
{
subject
}.
not_to
change
{
build
.
status
}
end
end
end
end
end
end
it
'schedules the build'
do
(
HasStatus
::
AVAILABLE_STATUSES
-
valid_statuses_for_when
).
each
do
|
status_for_prior_stages
|
Timecop
.
freeze
do
let
(
:current_status
)
{
status_for_prior_stages
}
expect
(
Ci
::
BuildScheduleWorker
)
.
to
receive
(
:perform_at
).
with
(
1
.
minute
.
since
,
build
.
id
)
subject
context
"when status for prior stages is
#{
status_for_prior_stages
}
"
do
%w[created pending]
.
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
when:
when_option
,
user:
user
,
project:
project
)
}
expect
(
build
).
to
be_scheduled
it
'skips the build'
do
expect
{
subject
}.
to
change
{
build
.
status
}.
to
(
'skipped'
)
end
end
end
(
HasStatus
::
AVAILABLE_STATUSES
-
%w[created pending]
).
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
when:
when_option
,
user:
user
,
project:
project
)
}
it
'does not change build status'
do
expect
{
subject
}.
not_to
change
{
build
.
status
}
end
end
end
end
end
end
end
end
end
shared_examples_for
'Actionizing properly'
do
|
valid_statuses_for_when
|
valid_statuses_for_when
.
each
do
|
status_for_prior_stages
|
context
"when status for prior stages is
#{
status_for_prior_stages
}
"
do
let
(
:current_status
)
{
status_for_prior_stages
}
%w[created]
.
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
:actionable
,
user:
user
,
project:
project
)
}
context
'when ci_enable_scheduled_build feature flag is disabled'
do
it
'enqueues the build'
do
before
do
expect
{
subject
}.
to
change
{
build
.
status
}.
to
(
'manual'
)
stub_feature_flags
(
ci_enable_scheduled_build:
false
)
end
end
end
%w[manual skipped pending running success failed canceled scheduled]
.
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
:actionable
,
user:
user
,
project:
project
)
}
it
'does not change the build status'
do
expect
{
subject
}.
not_to
change
{
build
.
status
}
end
end
end
end
end
end
(
HasStatus
::
AVAILABLE_STATUSES
-
valid_statuses_for_when
).
each
do
|
status_for_prior_stages
|
let
(
:current_status
)
{
status_for_prior_stages
}
it
'enqueues the build'
do
context
"when status for prior stages is
#{
status_for_prior_stages
}
"
do
subject
%w[created pending]
.
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
:actionable
,
user:
user
,
project:
project
)
}
expect
(
build
).
to
be_manual
it
'skips the build'
do
expect
{
subject
}.
to
change
{
build
.
status
}.
to
(
'skipped'
)
end
end
end
(
HasStatus
::
AVAILABLE_STATUSES
-
%w[created pending]
).
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
:actionable
,
user:
user
,
project:
project
)
}
it
'does not change build status'
do
expect
{
subject
}.
not_to
change
{
build
.
status
}
end
end
end
end
end
end
end
end
end
context
'when build is actionable'
do
shared_examples_for
'Scheduling properly'
do
|
valid_statuses_for_when
|
let
(
:build
)
{
create
(
:ci_build
,
:created
,
:actionable
,
user:
user
,
project:
project
)
}
valid_statuses_for_when
.
each
do
|
status_for_prior_stages
|
context
"when status for prior stages is
#{
status_for_prior_stages
}
"
do
let
(
:current_status
)
{
status_for_prior_stages
}
%w[created]
.
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
:schedulable
,
user:
user
,
project:
project
)
}
it
'enqueues the build'
do
expect
{
subject
}.
to
change
{
build
.
status
}.
to
(
'scheduled'
)
end
end
end
%w[manual skipped pending running success failed canceled scheduled]
.
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
:schedulable
,
user:
user
,
project:
project
)
}
it
'does not change the build status'
do
expect
{
subject
}.
not_to
change
{
build
.
status
}
end
end
end
end
end
it
'actionizes the build'
do
(
HasStatus
::
AVAILABLE_STATUSES
-
valid_statuses_for_when
).
each
do
|
status_for_prior_stages
|
subject
let
(
:current_status
)
{
status_for_prior_stages
}
expect
(
build
).
to
be_manual
context
"when status for prior stages is
#{
status_for_prior_stages
}
"
do
%w[created pending]
.
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
:schedulable
,
user:
user
,
project:
project
)
}
it
'skips the build'
do
expect
{
subject
}.
to
change
{
build
.
status
}.
to
(
'skipped'
)
end
end
end
(
HasStatus
::
AVAILABLE_STATUSES
-
%w[created pending]
).
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
:schedulable
,
user:
user
,
project:
project
)
}
it
'does not change build status'
do
expect
{
subject
}.
not_to
change
{
build
.
status
}
end
end
end
end
end
end
end
end
context
'when build
does not have any actions
'
do
context
'when build
has on_success option
'
do
let
(
:
build
)
{
create
(
:ci_build
,
:created
,
user:
user
,
project:
project
)
}
let
(
:
when_option
)
{
:on_success
}
it
'enqueues the build'
do
it_behaves_like
'Enqueuing properly'
,
%w[success skipped]
subject
end
context
'when build has on_failure option'
do
let
(
:when_option
)
{
:on_failure
}
it_behaves_like
'Enqueuing properly'
,
%w[failed]
end
context
'when build has always option'
do
let
(
:when_option
)
{
:always
}
it_behaves_like
'Enqueuing properly'
,
%w[success failed skipped]
end
context
'when build has manual option'
do
let
(
:when_option
)
{
:manual
}
it_behaves_like
'Actionizing properly'
,
%w[success skipped]
end
context
'when build has delayed option'
do
let
(
:when_option
)
{
:delayed
}
expect
(
build
).
to
be_pending
before
do
allow
(
Ci
::
BuildScheduleWorker
).
to
receive
(
:perform_at
)
{
}
end
end
it_behaves_like
'Scheduling properly'
,
%w[success skipped]
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