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
Kazuhiko Shiozaki
gitlab-ce
Commits
55701d9c
Commit
55701d9c
authored
Feb 19, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix specs
parent
921cfb66
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
60 deletions
+77
-60
spec/factories/ci/builds.rb
spec/factories/ci/builds.rb
+1
-1
spec/requests/api/builds_spec.rb
spec/requests/api/builds_spec.rb
+76
-59
No files found.
spec/factories/ci/builds.rb
View file @
55701d9c
...
@@ -53,7 +53,7 @@ FactoryGirl.define do
...
@@ -53,7 +53,7 @@ FactoryGirl.define do
tag
true
tag
true
end
end
factory
:ci_build_with_
trace
do
trait
:
trace
do
after
(
:create
)
do
|
build
,
evaluator
|
after
(
:create
)
do
|
build
,
evaluator
|
build
.
trace
=
'BUILD TRACE'
build
.
trace
=
'BUILD TRACE'
end
end
...
...
spec/requests/api/builds_spec.rb
View file @
55701d9c
...
@@ -4,173 +4,190 @@ describe API::API, api: true do
...
@@ -4,173 +4,190 @@ describe API::API, api: true do
include
ApiHelpers
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:api_user
)
{
user
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:developer
)
{
create
(
:project_member
,
user:
user
,
project:
project
,
access_level:
ProjectMember
::
DEVELOPER
)
}
let!
(
:developer
)
{
create
(
:project_member
,
user:
user
,
project:
project
,
access_level:
ProjectMember
::
DEVELOPER
)
}
let!
(
:reporter
)
{
create
(
:project_member
,
user:
user2
,
project:
project
,
access_level:
ProjectMember
::
REPORTER
)
}
let!
(
:reporter
)
{
create
(
:project_member
,
user:
user2
,
project:
project
,
access_level:
ProjectMember
::
REPORTER
)
}
let
(
:commit
)
{
create
(
:ci_commit
,
project:
project
)}
let
(
:commit
)
{
create
(
:ci_commit
,
project:
project
)}
let
(
:build
)
{
create
(
:ci_build
,
commit:
commit
)
}
let
(
:build
)
{
create
(
:ci_build
,
commit:
commit
)
}
let
(
:build_with_trace
)
{
create
(
:ci_build_with_trace
,
commit:
commit
)
}
let
(
:build_with_artifacts
)
{
create
(
:ci_build
,
:artifacts
,
commit:
commit
)
}
let
(
:build_canceled
)
{
create
(
:ci_build
,
:canceled
,
commit:
commit
)
}
describe
'GET /projects/:id/builds '
do
describe
'GET /projects/:id/builds '
do
let
(
:query
)
{
''
}
before
{
get
api
(
"/projects/
#{
project
.
id
}
/builds?
#{
query
}
"
,
api_user
)
}
context
'authorized user'
do
context
'authorized user'
do
it
'should return project builds'
do
it
'should return project builds'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
be_an
Array
end
end
it
'should
filter project with one scope element'
do
context
'
filter project with one scope element'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds?scope=pending"
,
user
)
let
(
:query
)
{
'scope=pending'
}
it
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
be_an
Array
end
end
end
it
'should
filter project with array of scope elements'
do
context
'
filter project with array of scope elements'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds?scope[0]=pending&scope[1]=running"
,
user
)
let
(
:query
)
{
'scope[0]=pending&scope[1]=running'
}
it
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
be_an
Array
end
end
end
it
'should
respond 400 when scope contains invalid state'
do
context
'
respond 400 when scope contains invalid state'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds?scope[0]=pending&scope[1]=unknown_status"
,
user
)
let
(
:query
)
{
'scope[0]=pending&scope[1]=unknown_status'
}
expect
(
response
.
status
).
to
eq
(
400
)
it
{
expect
(
response
.
status
).
to
eq
(
400
)
}
end
end
end
end
context
'unauthorized user'
do
context
'unauthorized user'
do
it
'should not return project builds'
do
let
(
:api_user
)
{
nil
}
get
api
(
"/projects/
#{
project
.
id
}
/builds"
)
it
'should not return project builds'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
end
end
end
describe
'GET /projects/:id/repository/commits/:sha/builds'
do
describe
'GET /projects/:id/repository/commits/:sha/builds'
do
context
'authorized user'
do
before
do
it
'should return project builds for specific commit'
do
project
.
ensure_ci_commit
(
commit
.
sha
)
project
.
ensure_ci_commit
(
commit
.
sha
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
sha
}
/builds"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
sha
}
/builds"
,
api_user
)
end
context
'authorized user'
do
it
'should return project builds for specific commit'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
be_an
Array
end
end
end
end
context
'unauthorized user'
do
context
'unauthorized user'
do
it
'should not return project builds'
do
let
(
:api_user
)
{
nil
}
project
.
ensure_ci_commit
(
commit
.
sha
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
sha
}
/builds"
)
it
'should not return project builds'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
end
end
end
describe
'GET /projects/:id/builds/:build_id'
do
describe
'GET /projects/:id/builds/:build_id'
do
before
{
get
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
"
,
api_user
)
}
context
'authorized user'
do
context
'authorized user'
do
it
'should return specific build data'
do
it
'should return specific build data'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
'test'
)
expect
(
json_response
[
'name'
]).
to
eq
(
'test'
)
end
end
end
end
context
'unauthorized user'
do
context
'unauthorized user'
do
it
'should not return specific build data'
do
let
(
:api_user
)
{
nil
}
get
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
"
)
it
'should not return specific build data'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
end
end
end
describe
'GET /projects/:id/builds/:build_id/artifacts'
do
describe
'GET /projects/:id/builds/:build_id/artifacts'
do
context
'authorized user'
do
before
{
get
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
/artifacts"
,
api_user
)
}
it
'should return specific build trace'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build_with_artifacts
.
id
}
/artifacts"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
context
'build with artifacts'
do
end
let
(
:build
)
{
create
(
:ci_build
,
:artifacts
,
commit:
commit
)
}
it
'should not return build artifacts if not uploaded'
do
context
'authorized user'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
/artifacts"
,
user
)
let
(
:download_headers
)
do
{
'Content-Transfer-Encoding'
=>
'binary'
,
'Content-Disposition'
=>
'attachment; filename=ci_build_artifacts.zip'
}
end
expect
(
response
.
status
).
to
eq
(
404
)
it
'should return specific build artifacts'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
headers
).
to
include
(
download_headers
)
end
end
end
end
context
'unauthorized user'
do
context
'unauthorized user'
do
it
'should not return specific build artifacts'
do
let
(
:api_user
)
{
nil
}
get
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build_with_artifacts
.
id
}
/trace"
)
it
'should not return specific build artifacts'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
end
end
end
it
'should not return build artifacts if not uploaded'
do
expect
(
response
.
status
).
to
eq
(
404
)
end
end
describe
'GET /projects/:id/builds/:build_id/trace'
do
describe
'GET /projects/:id/builds/:build_id/trace'
do
let
(
:build
)
{
create
(
:ci_build
,
:trace
,
commit:
commit
)
}
before
{
get
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
/trace"
,
api_user
)
}
context
'authorized user'
do
context
'authorized user'
do
it
'should return specific build trace'
do
it
'should return specific build trace'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build_with_trace
.
id
}
/trace"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
body
).
to
eq
(
build
_with_trace
.
trace
)
expect
(
response
.
body
).
to
eq
(
build
.
trace
)
end
end
end
end
context
'unauthorized user'
do
context
'unauthorized user'
do
it
'should not return specific build trace'
do
let
(
:api_user
)
{
nil
}
get
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build_with_trace
.
id
}
/trace"
)
it
'should not return specific build trace'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
end
end
end
describe
'POST /projects/:id/builds/:build_id/cancel'
do
describe
'POST /projects/:id/builds/:build_id/cancel'
do
before
{
post
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
/cancel"
,
api_user
)
}
context
'authorized user'
do
context
'authorized user'
do
context
'user with :update_build persmission'
do
context
'user with :update_build persmission'
do
it
'should cancel running or pending build'
do
it
'should cancel running or pending build'
do
post
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
/cancel"
,
user
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
project
.
builds
.
first
.
status
).
to
eq
(
'canceled'
)
expect
(
project
.
builds
.
first
.
status
).
to
eq
(
'canceled'
)
end
end
end
end
context
'user without :update_build permission'
do
context
'user without :update_build permission'
do
it
'should not cancel build'
do
let
(
:api_user
)
{
user2
}
post
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
/cancel"
,
user2
)
it
'should not cancel build'
do
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
end
end
end
end
context
'unauthorized user'
do
context
'unauthorized user'
do
it
'should not cancel build'
do
let
(
:api_user
)
{
nil
}
post
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
/cancel"
)
it
'should not cancel build'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
end
end
end
describe
'POST /projects/:id/builds/:build_id/retry'
do
describe
'POST /projects/:id/builds/:build_id/retry'
do
let
(
:build
)
{
create
(
:ci_build
,
:canceled
,
commit:
commit
)
}
before
{
post
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build
.
id
}
/retry"
,
api_user
)
}
context
'authorized user'
do
context
'authorized user'
do
context
'user with :update_build per
s
mission'
do
context
'user with :update_build permission'
do
it
'should retry non-running build'
do
it
'should retry non-running build'
do
post
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build_canceled
.
id
}
/retry"
,
user
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
project
.
builds
.
first
.
status
).
to
eq
(
'canceled'
)
expect
(
project
.
builds
.
first
.
status
).
to
eq
(
'canceled'
)
expect
(
json_response
[
'status'
]).
to
eq
(
'pending'
)
expect
(
json_response
[
'status'
]).
to
eq
(
'pending'
)
...
@@ -178,18 +195,18 @@ describe API::API, api: true do
...
@@ -178,18 +195,18 @@ describe API::API, api: true do
end
end
context
'user without :update_build permission'
do
context
'user without :update_build permission'
do
it
'should not retry build'
do
let
(
:api_user
)
{
user2
}
post
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build_canceled
.
id
}
/retry"
,
user2
)
it
'should not retry build'
do
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
end
end
end
end
context
'unauthorized user'
do
context
'unauthorized user'
do
it
'should not retry build'
do
let
(
:api_user
)
{
nil
}
post
api
(
"/projects/
#{
project
.
id
}
/builds/
#{
build_canceled
.
id
}
/retry"
)
it
'should not retry build'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
.
status
).
to
eq
(
401
)
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