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
ec0d1f5f
Commit
ec0d1f5f
authored
Nov 10, 2020
by
lauraMon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored a little and added more specs
parent
214a372a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
10 deletions
+15
-10
lib/api/lint.rb
lib/api/lint.rb
+2
-3
spec/requests/api/lint_spec.rb
spec/requests/api/lint_spec.rb
+13
-7
No files found.
lib/api/lint.rb
View file @
ec0d1f5f
...
...
@@ -13,14 +13,13 @@ module API
post
'/lint'
do
result
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
params
[
:content
],
user:
current_user
).
execute
error
=
result
.
errors
.
first
warning
=
result
.
warnings
.
first
status
200
response
=
if
error
.
blank?
{
status:
'valid'
,
errors:
[],
warnings:
[
warning
]
}
{
status:
'valid'
,
errors:
[],
warnings:
result
.
warnings
}
else
{
status:
'invalid'
,
errors:
[
error
],
warnings:
[]
}
{
status:
'invalid'
,
errors:
[
error
],
warnings:
result
.
warnings
}
end
response
.
tap
do
|
response
|
...
...
spec/requests/api/lint_spec.rb
View file @
ec0d1f5f
...
...
@@ -9,12 +9,13 @@ RSpec.describe API::Lint do
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
end
it
'passes validation'
do
it
'passes validation
without warnings
'
do
post
api
(
'/ci/lint'
),
params:
{
content:
yaml_content
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
be_an
Hash
expect
(
json_response
[
'status'
]).
to
eq
(
'valid'
)
expect
(
json_response
[
'warnings'
]).
to
eq
([])
expect
(
json_response
[
'errors'
]).
to
eq
([])
end
...
...
@@ -26,8 +27,8 @@ RSpec.describe API::Lint do
end
end
context
'with valid .gitlab-ci.yaml
but
with warnings'
do
let
(
:yaml_content
)
{
{
job:
{
script:
'ls'
,
rules:
[{
when:
'always'
}]
}
}.
to_yaml
}
context
'with valid .gitlab-ci.yaml with warnings'
do
let
(
:yaml_content
)
{
{
job:
{
script:
'ls'
,
rules:
[{
when:
'always'
}]
}
}.
to_yaml
}
it
'passes validation but raises a warning'
do
post
api
(
'/ci/lint'
),
params:
{
content:
yaml_content
}
...
...
@@ -48,6 +49,7 @@ RSpec.describe API::Lint do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'status'
]).
to
eq
(
'invalid'
)
expect
(
json_response
[
'warnings'
]).
to
eq
([])
expect
(
json_response
[
'errors'
]).
to
eq
([
'Invalid configuration format'
])
end
...
...
@@ -67,6 +69,7 @@ RSpec.describe API::Lint do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'status'
]).
to
eq
(
'invalid'
)
expect
(
json_response
[
'warnings'
]).
to
eq
([])
expect
(
json_response
[
'errors'
]).
to
eq
([
'jobs config should contain at least one visible job'
])
end
...
...
@@ -106,7 +109,7 @@ RSpec.describe API::Lint do
end
end
RSpec
.
shared_examples
'valid config'
do
RSpec
.
shared_examples
'valid config
without warnings
'
do
it
'passes validation'
do
ci_lint
...
...
@@ -118,6 +121,7 @@ RSpec.describe API::Lint do
expect
(
json_response
).
to
be_an
Hash
expect
(
json_response
[
'merged_yaml'
]).
to
eq
(
expected_yaml
)
expect
(
json_response
[
'valid'
]).
to
eq
(
true
)
expect
(
json_response
[
'warnings'
]).
to
eq
([])
expect
(
json_response
[
'errors'
]).
to
eq
([])
end
end
...
...
@@ -129,6 +133,7 @@ RSpec.describe API::Lint do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'merged_yaml'
]).
to
eq
(
yaml_content
)
expect
(
json_response
[
'valid'
]).
to
eq
(
false
)
expect
(
json_response
[
'warnings'
]).
to
eq
([])
expect
(
json_response
[
'errors'
]).
to
eq
([
'jobs config should contain at least one visible job'
])
end
end
...
...
@@ -181,6 +186,7 @@ RSpec.describe API::Lint do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'merged_yaml'
]).
to
eq
(
nil
)
expect
(
json_response
[
'valid'
]).
to
eq
(
false
)
expect
(
json_response
[
'warnings'
]).
to
eq
([])
expect
(
json_response
[
'errors'
]).
to
eq
([
'Insufficient permissions to create a new pipeline'
])
end
end
...
...
@@ -210,7 +216,7 @@ RSpec.describe API::Lint do
)
end
it_behaves_like
'valid config'
it_behaves_like
'valid config
without warnings
'
end
end
end
...
...
@@ -266,13 +272,13 @@ RSpec.describe API::Lint do
context
'when running as dry run'
do
let
(
:dry_run
)
{
true
}
it_behaves_like
'valid config'
it_behaves_like
'valid config
without warnings
'
end
context
'when running static validation'
do
let
(
:dry_run
)
{
false
}
it_behaves_like
'valid config'
it_behaves_like
'valid config
without warnings
'
end
context
'With warnings'
do
...
...
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