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
895ca3a7
Commit
895ca3a7
authored
Aug 23, 2016
by
Katarzyna Kobierska
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for API CI Lint
parent
fb1c7254
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
24 deletions
+59
-24
lib/ci/api/entities.rb
lib/ci/api/entities.rb
+0
-7
lib/ci/api/lint.rb
lib/ci/api/lint.rb
+24
-9
spec/requests/ci/api/lint_spec.rb
spec/requests/ci/api/lint_spec.rb
+35
-8
No files found.
lib/ci/api/entities.rb
View file @
895ca3a7
...
@@ -59,13 +59,6 @@ module Ci
...
@@ -59,13 +59,6 @@ module Ci
expose
:id
,
:variables
expose
:id
,
:variables
expose
:pipeline
,
using:
Commit
,
as: :commit
expose
:pipeline
,
using:
Commit
,
as: :commit
end
end
class
Lint
<
Grape
::
Entity
expose
:content
expose
:status
expose
:builds
expose
:stages
end
end
end
end
end
end
end
lib/ci/api/lint.rb
View file @
895ca3a7
...
@@ -4,19 +4,34 @@ module Ci
...
@@ -4,19 +4,34 @@ module Ci
before
{
authenticate!
}
before
{
authenticate!
}
resources
:lint
do
resources
:lint
do
post
do
post
do
content
=
params
[
:content
]
begin
response
=
{}
@content
=
params
[
:content
]
if
@content
@config_processor
=
Ci
::
GitlabCiYamlProcessor
.
new
(
@content
)
@stages
=
@config_processor
.
stages
@builds
=
@config_processor
.
builds
if
content
response
=
{
config_processor
=
Ci
::
GitlabCiYamlProcessor
.
new
(
content
)
content:
@content
,
stages
=
config_processor
.
stages
status:
"syntax is correct"
builds
=
config_processor
.
builds
}
status
=
true
response
=
{
status:
status
,
stages:
stages
,
builds:
builds
}
stage_builds
=
@stages
.
each
do
|
stage
|
response
[
"
#{
stage
}
"
]
=
@builds
.
select
{
|
build
|
build
[
:stage
]
==
stage
}
end
else
render_api_error!
(
"Please provide content of .gitlab-ci.yml"
,
400
)
end
end
response
response
rescue
Ci
::
GitlabCiYamlProcessor
::
ValidationError
,
Psych
::
SyntaxError
=>
e
error!
({
content:
@content
,
status:
"syntax is incorrect"
,
message:
e
.
message
})
end
end
end
end
end
end
end
...
...
spec/requests/ci/api/lint_spec.rb
View file @
895ca3a7
...
@@ -3,20 +3,47 @@ require 'spec_helper'
...
@@ -3,20 +3,47 @@ require 'spec_helper'
describe
Ci
::
API
::
API
do
describe
Ci
::
API
::
API
do
include
ApiHelpers
include
ApiHelpers
let
(
:content
)
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:yaml_content
)
do
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
end
end
describe
"Builds API for Lint"
do
describe
'POST /ci/lint'
do
describe
'POST /ci/lint'
do
before
{
content
}
context
"with valid .gitlab-ci.yaml content"
do
context
"authorized user"
do
it
"validate content"
do
post
ci_api
(
'/lint'
),
{
private_token:
user
.
private_token
,
content:
yaml_content
}
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
).
to
be_an
Hash
expect
(
json_response
[
'status'
]).
to
eq
(
'syntax is correct'
)
end
end
context
"with valid .gitlab-ci.yaml file"
do
context
"unauthorized user"
do
it
"has success status"
do
it
"does not validate content"
do
# binding.pry
post
ci_api
(
'/lint'
),
{
content:
yaml_content
}
expect
(
response
).
to
have_content
(
true
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
end
context
"with invalid .gitlab_ci.yml content"
do
it
"validate content"
do
post
ci_api
(
'/lint'
),
{
private_token:
user
.
private_token
,
content:
'invalid content'
}
expect
(
response
).
to
have_http_status
(
500
)
expect
(
json_response
[
'status'
]).
to
eq
(
'syntax is incorrect'
)
end
end
context
"no content"
do
it
"shows error message"
do
post
ci_api
(
'/lint'
),
{
private_token:
user
.
private_token
}
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Please provide content of .gitlab-ci.yml'
)
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