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
Jérome Perrin
gitlab-ce
Commits
953a1094
Commit
953a1094
authored
Dec 06, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Ci::Stage specs
parent
401c155e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
165 additions
and
9 deletions
+165
-9
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+4
-0
lib/gitlab/data_builder/pipeline.rb
lib/gitlab/data_builder/pipeline.rb
+1
-1
spec/factories/ci/stages.rb
spec/factories/ci/stages.rb
+13
-0
spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
+2
-2
spec/lib/gitlab/ci/status/stage/common_spec.rb
spec/lib/gitlab/ci/status/stage/common_spec.rb
+2
-2
spec/lib/gitlab/ci/status/stage/factory_spec.rb
spec/lib/gitlab/ci/status/stage/factory_spec.rb
+6
-4
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+4
-0
spec/models/ci/stage_spec.rb
spec/models/ci/stage_spec.rb
+133
-0
No files found.
app/models/ci/pipeline.rb
View file @
953a1094
...
...
@@ -104,6 +104,10 @@ module Ci
statuses
.
select
(
:stage
).
distinct
.
count
end
def
stages_name
statuses
.
order
(
:stage_idx
).
distinct
.
pluck
(
:stage
)
end
def
stages
status_sql
=
statuses
.
latest
.
where
(
'stage=sg.stage'
).
status_sql
...
...
lib/gitlab/data_builder/pipeline.rb
View file @
953a1094
...
...
@@ -22,7 +22,7 @@ module Gitlab
sha:
pipeline
.
sha
,
before_sha:
pipeline
.
before_sha
,
status:
pipeline
.
status
,
stages:
pipeline
.
stages
.
map
(
&
:name
)
,
stages:
pipeline
.
stages
_name
,
created_at:
pipeline
.
created_at
,
finished_at:
pipeline
.
finished_at
,
duration:
pipeline
.
duration
...
...
spec/factories/ci/stages.rb
0 → 100644
View file @
953a1094
FactoryGirl
.
define
do
factory
:ci_stage
,
class:
Ci
::
Stage
do
transient
do
name
'test'
status
nil
pipeline
factory: :ci_empty_pipeline
end
initialize_with
do
Ci
::
Stage
.
new
(
pipeline
,
name:
name
,
status:
status
)
end
end
end
spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
View file @
953a1094
...
...
@@ -21,7 +21,7 @@ describe Gitlab::Ci::Status::Pipeline::Factory do
Gitlab
::
Ci
::
Status
.
const_get
(
core_status
.
capitalize
))
end
it
'extends core status with common
pipelin
e methods'
do
it
'extends core status with common
stag
e methods'
do
expect
(
status
).
to
have_details
expect
(
status
).
not_to
have_action
expect
(
status
.
details_path
)
...
...
@@ -45,7 +45,7 @@ describe Gitlab::Ci::Status::Pipeline::Factory do
.
to
be_a
Gitlab
::
Ci
::
Status
::
Pipeline
::
SuccessWithWarnings
end
it
'extends core status with common
pipelin
e methods'
do
it
'extends core status with common
stag
e methods'
do
expect
(
status
).
to
have_details
end
end
...
...
spec/lib/gitlab/ci/status/stage/common_spec.rb
View file @
953a1094
require
'spec_helper'
describe
Gitlab
::
Ci
::
Status
::
Stage
::
Common
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
let
(
:stage
)
{
Ci
::
Stage
.
new
(
pipeline
,
name:
'test'
)
}
let
(
:pipeline
)
{
create
(
:ci_
empty_
pipeline
)
}
let
(
:stage
)
{
build
(
:ci_stage
,
pipeline:
pipeline
,
name:
'test'
)
}
subject
do
Class
.
new
(
Gitlab
::
Ci
::
Status
::
Core
)
...
...
spec/lib/gitlab/ci/status/stage/factory_spec.rb
View file @
953a1094
require
'spec_helper'
describe
Gitlab
::
Ci
::
Status
::
Stage
::
Factory
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
let
(
:stage
)
{
Ci
::
Stage
.
new
(
pipeline
,
name:
'test'
)
}
let
(
:pipeline
)
{
create
(
:ci_
empty_
pipeline
)
}
let
(
:stage
)
{
build
(
:ci_stage
,
pipeline:
pipeline
,
name:
'test'
)
}
subject
do
described_class
.
new
(
stage
)
...
...
@@ -15,8 +15,10 @@ describe Gitlab::Ci::Status::Stage::Factory do
context
'when stage has a core status'
do
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
core_status
|
context
"when core status is
#{
core_status
}
"
do
let!
(
:build
)
do
before
do
create
(
:ci_build
,
pipeline:
pipeline
,
stage:
'test'
,
status:
core_status
)
create
(
:commit_status
,
pipeline:
pipeline
,
stage:
'test'
,
status:
core_status
)
create
(
:ci_build
,
pipeline:
pipeline
,
stage:
'build'
,
status: :failed
)
end
it
"fabricates a core status
#{
core_status
}
"
do
...
...
@@ -24,7 +26,7 @@ describe Gitlab::Ci::Status::Stage::Factory do
Gitlab
::
Ci
::
Status
.
const_get
(
core_status
.
capitalize
))
end
it
'extends core status with common
pipelin
e methods'
do
it
'extends core status with common
stag
e methods'
do
expect
(
status
).
to
have_details
expect
(
status
.
details_path
).
to
include
"pipelines/
#{
pipeline
.
id
}
"
expect
(
status
.
details_path
).
to
include
"#
#{
stage
.
name
}
"
...
...
spec/models/ci/pipeline_spec.rb
View file @
953a1094
...
...
@@ -142,6 +142,10 @@ describe Ci::Pipeline, models: true do
expect
(
pipeline
.
stages_count
).
to
eq
(
3
)
end
it
'returns a valid names of stages'
do
expect
(
pipeline
.
stages_name
).
to
eq
([
'build'
,
'test'
,
'deploy'
])
end
context
'stages with statuses'
do
let
(
:statuses
)
do
subject
.
map
do
|
stage
|
...
...
spec/models/ci/stage_spec.rb
0 → 100644
View file @
953a1094
require
'spec_helper'
describe
Ci
::
Stage
,
models:
true
do
let
(
:stage
)
{
build
(
:ci_stage
)
}
let
(
:pipeline
)
{
stage
.
pipeline
}
let
(
:stage_name
)
{
stage
.
name
}
describe
'#expectations'
do
subject
{
stage
}
it
{
is_expected
.
to
include_module
(
StaticModel
)
}
it
{
is_expected
.
to
respond_to
(
:pipeline
)
}
it
{
is_expected
.
to
respond_to
(
:name
)
}
it
{
is_expected
.
to
delegate_method
(
:project
).
to
(
:pipeline
)
}
end
describe
'#statuses'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
)
}
let!
(
:commit_status
)
{
create_job
(
:commit_status
)
}
let!
(
:other_build
)
{
create_job
(
:ci_build
,
stage:
'other stage'
)
}
subject
{
stage
.
statuses
}
it
"returns only matching statuses"
do
is_expected
.
to
contain_exactly
(
stage_build
,
commit_status
)
end
end
describe
'#builds'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
)
}
let!
(
:commit_status
)
{
create_job
(
:commit_status
)
}
subject
{
stage
.
builds
}
it
"returns only builds"
do
is_expected
.
to
contain_exactly
(
stage_build
)
end
end
describe
'#status'
do
subject
{
stage
.
status
}
context
'if status is already defined'
do
let
(
:stage
)
{
build
(
:ci_stage
,
status:
'success'
)
}
it
"returns defined status"
do
is_expected
.
to
eq
(
'success'
)
end
end
context
'if status has to be calculated'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
,
status: :failed
)
}
it
"returns status of a build"
do
is_expected
.
to
eq
(
'failed'
)
end
context
'and builds are retried'
do
let!
(
:new_build
)
{
create_job
(
:ci_build
,
status: :success
)
}
it
"returns status of latest build"
do
is_expected
.
to
eq
(
'success'
)
end
end
end
end
describe
'#detailed_status'
do
subject
{
stage
.
detailed_status
}
context
'when build is created'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
,
status: :created
)
}
it
'returns detailed status for created stage'
do
expect
(
subject
.
text
).
to
eq
'created'
end
end
context
'when build is pending'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
,
status: :pending
)
}
it
'returns detailed status for pending stage'
do
expect
(
subject
.
text
).
to
eq
'pending'
end
end
context
'when build is running'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
,
status: :running
)
}
it
'returns detailed status for running stage'
do
expect
(
subject
.
text
).
to
eq
'running'
end
end
context
'when build is successful'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
,
status: :success
)
}
it
'returns detailed status for successful stage'
do
expect
(
subject
.
text
).
to
eq
'passed'
end
end
context
'when build is failed'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
,
status: :failed
)
}
it
'returns detailed status for failed stage'
do
expect
(
subject
.
text
).
to
eq
'failed'
end
end
context
'when build is canceled'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
,
status: :canceled
)
}
it
'returns detailed status for canceled stage'
do
expect
(
subject
.
text
).
to
eq
'canceled'
end
end
context
'when build is skipped'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
,
status: :skipped
)
}
it
'returns detailed status for skipped stage'
do
expect
(
subject
.
text
).
to
eq
'skipped'
end
end
end
def
create_job
(
type
,
status:
'success'
,
stage:
stage_name
)
create
(
type
,
pipeline:
pipeline
,
stage:
stage
,
status:
status
)
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