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
f262b8f3
Commit
f262b8f3
authored
Oct 10, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve specs for Ci::ProcessBuildService
parent
e409834f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
161 deletions
+90
-161
spec/services/ci/process_build_service_spec.rb
spec/services/ci/process_build_service_spec.rb
+90
-161
No files found.
spec/services/ci/process_build_service_spec.rb
View file @
f262b8f3
...
@@ -2,141 +2,40 @@
...
@@ -2,141 +2,40 @@
require
'spec_helper'
require
'spec_helper'
describe
Ci
::
ProcessBuildService
,
'#execute'
do
describe
Ci
::
ProcessBuildService
,
'#execute'
do
VALID_STATUSES_WHEN_ON_SUCCESS
=
%w[success skipped]
.
freeze
VALID_STATUSES_WHEN_ON_FAILURE
=
%w[failed]
.
freeze
VALID_STATUSES_WHEN_ALWAYS
=
%w[success failed skipped]
.
freeze
VALID_STATUSES_WHEN_MANUAL
=
%w[success skipped]
.
freeze
VALID_STATUSES_WHEN_DELAYED
=
%w[success skipped]
.
freeze
SKIPPABLE_STATUES
=
%w[created pending]
.
freeze
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
subject
{
described_class
.
new
(
project
,
user
).
execute
(
build
,
current_statu
s
)
}
subject
{
described_class
.
new
(
project
,
user
).
execute
(
build
,
status_for_prior_stage
s
)
}
before
do
before
do
project
.
add_maintainer
(
user
)
project
.
add_maintainer
(
user
)
end
end
shared_examples_for
'Enqueuing properly'
do
|
valid_statuses_for_when
|
shared_examples_for
'Change the build status'
do
|
when_option:
nil
,
current_statuses:
nil
,
from_statuses
:,
to_status
:,
factory_options:
nil
|
valid_statuses_for_when
.
each
do
|
status_for_prior_stages
|
current_statuses
.
each
do
|
current_status
|
context
"when status for prior stages is
#{
status_for_prior_stages
}
"
do
context
"when status for prior stages is
#{
current_status
}
"
do
let
(
:current_status
)
{
status_for_prior_stages
}
let
(
:status_for_prior_stages
)
{
current_status
}
%w[created skipped manual scheduled]
.
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
'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
(
HasStatus
::
AVAILABLE_STATUSES
-
valid_statuses_for_when
).
each
do
|
status_for_prior_stages
|
let
(
:current_status
)
{
status_for_prior_stages
}
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
)
}
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
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
)
}
it
'enqueues the build'
do
expect
{
subject
}.
to
change
{
build
.
status
}.
to
(
'manual'
)
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
(
HasStatus
::
AVAILABLE_STATUSES
-
valid_statuses_for_when
).
each
do
|
status_for_prior_stages
|
let
(
:current_status
)
{
status_for_prior_stages
}
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
,
:actionable
,
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
,
: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
shared_examples_for
'Scheduling 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
|
from_statuses
.
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
:schedulable
,
user:
user
,
project:
project
)
}
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
*
factory_options
,
when:
when_option
,
user:
user
,
project:
project
)
}
it
'
enqueues the build
'
do
it
'
changes the build status
'
do
expect
{
subject
}.
to
change
{
build
.
status
}.
to
(
'scheduled'
)
expect
{
subject
}.
to
change
{
build
.
status
}.
to
(
to_status
)
end
end
end
end
end
end
%w[manual skipped pending running success failed canceled scheduled]
.
each
do
|
status
|
(
HasStatus
::
AVAILABLE_STATUSES
-
from_statuses
)
.
each
do
|
status
|
context
"when build status is
#{
status
}
"
do
context
"when build status is
#{
status
}
"
do
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
:schedulable
,
user:
user
,
project:
project
)
}
let
(
:build
)
{
create
(
:ci_build
,
status
.
to_sym
,
*
factory_options
,
when:
when_option
,
user:
user
,
project:
project
)
}
it
'does not change the build status'
do
it
'does not change the build status'
do
expect
{
subject
}.
not_to
change
{
build
.
status
}
expect
{
subject
}.
not_to
change
{
build
.
status
}
...
@@ -145,61 +44,67 @@ describe Ci::ProcessBuildService, '#execute' do
...
@@ -145,61 +44,67 @@ describe Ci::ProcessBuildService, '#execute' do
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
}
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
context
'when build has on_success option'
do
context
'when build has on_success option'
do
let
(
:when_option
)
{
:on_success
}
it_behaves_like
'Change the build status'
,
when_option: :on_success
,
current_statuses:
VALID_STATUSES_WHEN_ON_SUCCESS
,
from_statuses:
%w[created skipped manual scheduled]
,
to_status:
'pending'
it_behaves_like
'Enqueuing properly'
,
%w[success skipped]
it_behaves_like
'Change the build status'
,
when_option: :on_success
,
current_statuses:
(
HasStatus
::
AVAILABLE_STATUSES
-
VALID_STATUSES_WHEN_ON_SUCCESS
),
from_statuses:
SKIPPABLE_STATUES
,
to_status:
'skipped'
end
end
context
'when build has on_failure option'
do
context
'when build has on_failure option'
do
let
(
:when_option
)
{
:on_failure
}
it_behaves_like
'Change the build status'
,
when_option: :on_failure
,
current_statuses:
VALID_STATUSES_WHEN_ON_FAILURE
,
from_statuses:
%w[created skipped manual scheduled]
,
to_status:
'pending'
it_behaves_like
'Enqueuing properly'
,
%w[failed]
it_behaves_like
'Change the build status'
,
when_option: :on_failure
,
current_statuses:
(
HasStatus
::
AVAILABLE_STATUSES
-
VALID_STATUSES_WHEN_ON_FAILURE
),
from_statuses:
SKIPPABLE_STATUES
,
to_status:
'skipped'
end
end
context
'when build has always option'
do
context
'when build has always option'
do
let
(
:when_option
)
{
:always
}
it_behaves_like
'Change the build status'
,
when_option: :always
,
current_statuses:
VALID_STATUSES_WHEN_ALWAYS
,
from_statuses:
%w[created skipped manual scheduled]
,
to_status:
'pending'
it_behaves_like
'Enqueuing properly'
,
%w[success failed skipped]
it_behaves_like
'Change the build status'
,
when_option: :always
,
current_statuses:
(
HasStatus
::
AVAILABLE_STATUSES
-
VALID_STATUSES_WHEN_ALWAYS
),
from_statuses:
SKIPPABLE_STATUES
,
to_status:
'skipped'
end
end
context
'when build has manual option'
do
context
'when build has manual option'
do
let
(
:when_option
)
{
:manual
}
it_behaves_like
'Change the build status'
,
when_option: :manual
,
current_statuses:
VALID_STATUSES_WHEN_MANUAL
,
from_statuses:
%w[created]
,
to_status:
'manual'
,
factory_options:
%i[actionable]
it_behaves_like
'Actionizing properly'
,
%w[success skipped]
it_behaves_like
'Change the build status'
,
when_option: :manual
,
current_statuses:
(
HasStatus
::
AVAILABLE_STATUSES
-
VALID_STATUSES_WHEN_ON_SUCCESS
),
from_statuses:
SKIPPABLE_STATUES
,
to_status:
'skipped'
,
factory_options:
%i[actionable]
end
end
context
'when build has delayed option'
do
context
'when build has delayed option'
do
let
(
:when_option
)
{
:delayed
}
before
do
before
do
allow
(
Ci
::
BuildScheduleWorker
).
to
receive
(
:perform_at
)
{
}
allow
(
Ci
::
BuildScheduleWorker
).
to
receive
(
:perform_at
)
{
}
end
end
...
@@ -209,7 +114,19 @@ describe Ci::ProcessBuildService, '#execute' do
...
@@ -209,7 +114,19 @@ describe Ci::ProcessBuildService, '#execute' do
stub_feature_flags
(
ci_enable_scheduled_build:
true
)
stub_feature_flags
(
ci_enable_scheduled_build:
true
)
end
end
it_behaves_like
'Scheduling properly'
,
%w[success skipped]
it_behaves_like
'Change the build status'
,
when_option: :delayed
,
current_statuses:
VALID_STATUSES_WHEN_DELAYED
,
from_statuses:
%w[created]
,
to_status:
'scheduled'
,
factory_options:
%i[schedulable]
it_behaves_like
'Change the build status'
,
when_option: :delayed
,
current_statuses:
(
HasStatus
::
AVAILABLE_STATUSES
-
VALID_STATUSES_WHEN_ON_SUCCESS
),
from_statuses:
SKIPPABLE_STATUES
,
to_status:
'skipped'
,
factory_options:
%i[schedulable]
end
end
context
'when ci_enable_scheduled_build is enabled'
do
context
'when ci_enable_scheduled_build is enabled'
do
...
@@ -217,7 +134,19 @@ describe Ci::ProcessBuildService, '#execute' do
...
@@ -217,7 +134,19 @@ describe Ci::ProcessBuildService, '#execute' do
stub_feature_flags
(
ci_enable_scheduled_build:
false
)
stub_feature_flags
(
ci_enable_scheduled_build:
false
)
end
end
it_behaves_like
'Actionizing properly'
,
%w[success skipped]
it_behaves_like
'Change the build status'
,
when_option: :delayed
,
current_statuses:
VALID_STATUSES_WHEN_DELAYED
,
from_statuses:
%w[created]
,
to_status:
'manual'
,
factory_options:
%i[schedulable]
it_behaves_like
'Change the build status'
,
when_option: :delayed
,
current_statuses:
(
HasStatus
::
AVAILABLE_STATUSES
-
VALID_STATUSES_WHEN_ON_SUCCESS
),
from_statuses:
SKIPPABLE_STATUES
,
to_status:
'skipped'
,
factory_options:
%i[schedulable]
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