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
d6e6b56d
Commit
d6e6b56d
authored
Feb 15, 2019
by
Gilbert Roulot
Committed by
Kamil Trzciński
Feb 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add schema matching for API responses
Match API responses with schemas in the spec files.
parent
1ba3c45e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
2 deletions
+59
-2
ee/app/models/ee/ci/build.rb
ee/app/models/ee/ci/build.rb
+4
-0
ee/spec/fixtures/api/schemas/managed_licenses.json
ee/spec/fixtures/api/schemas/managed_licenses.json
+4
-0
ee/spec/models/ci/build_spec.rb
ee/spec/models/ci/build_spec.rb
+30
-0
ee/spec/models/ci/pipeline_spec.rb
ee/spec/models/ci/pipeline_spec.rb
+8
-0
ee/spec/requests/api/managed_licenses_spec.rb
ee/spec/requests/api/managed_licenses_spec.rb
+9
-2
ee/spec/services/ci/compare_license_management_reports_service_spec.rb
...ces/ci/compare_license_management_reports_service_spec.rb
+4
-0
No files found.
ee/app/models/ee/ci/build.rb
View file @
d6e6b56d
...
...
@@ -81,6 +81,10 @@ module EE
def
collect_license_management_reports!
(
license_management_report
)
each_report
(
::
Ci
::
JobArtifact
::
LICENSE_MANAGEMENT_REPORT_FILE_TYPES
)
do
|
file_type
,
blob
|
next
if
::
Feature
.
disabled?
(
:parse_license_management_reports
,
default_enabled:
true
)
next
unless
project
.
feature_available?
(
:license_management
)
::
Gitlab
::
Ci
::
Parsers
.
fabricate!
(
file_type
).
parse!
(
blob
,
license_management_report
)
end
...
...
ee/spec/fixtures/api/schemas/managed_licenses.json
0 → 100644
View file @
d6e6b56d
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"software_license_policy.json"
}
}
ee/spec/models/ci/build_spec.rb
View file @
d6e6b56d
...
...
@@ -265,6 +265,10 @@ describe Ci::Build do
let
(
:license_management_report
)
{
Gitlab
::
Ci
::
Reports
::
LicenseManagement
::
Report
.
new
}
before
do
stub_licensed_features
(
license_management:
true
)
end
it
{
expect
(
license_management_report
.
licenses
.
count
).
to
eq
(
0
)
}
context
'when build has a license management report'
do
...
...
@@ -291,6 +295,32 @@ describe Ci::Build do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Ci
::
Parsers
::
LicenseManagement
::
LicenseManagement
::
LicenseManagementParserError
)
end
end
context
'when Feature flag is disabled for License Management reports parsing'
do
before
do
stub_feature_flags
(
parse_license_management_reports:
false
)
create
(
:ee_ci_job_artifact
,
:license_management
,
job:
job
,
project:
job
.
project
)
end
it
'does NOT parse license management report'
do
subject
expect
(
license_management_report
.
licenses
.
count
).
to
eq
(
0
)
end
end
context
'when the license management feature is disabled'
do
before
do
stub_licensed_features
(
license_management:
false
)
create
(
:ee_ci_job_artifact
,
:license_management
,
job:
job
,
project:
job
.
project
)
end
it
'does NOT parse license management report'
do
subject
expect
(
license_management_report
.
licenses
.
count
).
to
eq
(
0
)
end
end
end
end
end
ee/spec/models/ci/pipeline_spec.rb
View file @
d6e6b56d
...
...
@@ -326,6 +326,10 @@ describe Ci::Pipeline do
describe
'#has_license_management_reports?'
do
subject
{
pipeline
.
has_license_management_reports?
}
before
do
stub_licensed_features
(
license_management:
true
)
end
context
'when pipeline has builds with license_management reports'
do
before
do
create
(
:ee_ci_build
,
:license_management
,
pipeline:
pipeline
,
project:
project
)
...
...
@@ -368,6 +372,10 @@ describe Ci::Pipeline do
describe
'#license_management_reports'
do
subject
{
pipeline
.
license_management_report
}
before
do
stub_licensed_features
(
license_management:
true
)
end
context
'when pipeline has multiple builds with license management reports'
do
let!
(
:build_1
)
{
create
(
:ci_build
,
:success
,
name:
'license_management'
,
pipeline:
pipeline
,
project:
project
)
}
let!
(
:build_2
)
{
create
(
:ci_build
,
:success
,
name:
'license_management2'
,
pipeline:
pipeline
,
project:
project
)
}
...
...
ee/spec/requests/api/managed_licenses_spec.rb
View file @
d6e6b56d
...
...
@@ -48,11 +48,12 @@ describe API::ManagedLicenses do
end
end
context
'authorized user with proper permissions'
do
context
'
with an
authorized user with proper permissions'
do
it
'returns project managed licenses'
do
get
api
(
"/projects/
#{
project
.
id
}
/managed_licenses"
,
dev_user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'managed_licenses'
,
dir:
'ee'
)
expect
(
json_response
).
to
be_a
(
Array
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
software_license_policy
.
id
)
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
software_license_policy
.
name
)
...
...
@@ -60,11 +61,12 @@ describe API::ManagedLicenses do
end
end
context
'authorized user without read permissions'
do
context
'
with
authorized user without read permissions'
do
it
'returns project managed licenses to users with read permissions'
do
get
api
(
"/projects/
#{
project
.
id
}
/managed_licenses"
,
reporter_user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'managed_licenses'
,
dir:
'ee'
)
expect
(
json_response
).
to
be_a
(
Array
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
software_license_policy
.
id
)
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
software_license_policy
.
name
)
...
...
@@ -87,6 +89,7 @@ describe API::ManagedLicenses do
get
api
(
"/projects/
#{
project
.
id
}
/managed_licenses/
#{
software_license_policy
.
id
}
"
,
dev_user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'software_license_policy'
,
dir:
'ee'
)
expect
(
json_response
[
'id'
]).
to
eq
(
software_license_policy
.
id
)
expect
(
json_response
[
'name'
]).
to
eq
(
software_license_policy
.
name
)
expect
(
json_response
[
'approval_status'
]).
to
eq
(
software_license_policy
.
approval_status
)
...
...
@@ -97,6 +100,7 @@ describe API::ManagedLicenses do
get
api
(
"/projects/
#{
project
.
id
}
/managed_licenses/
#{
escaped_name
}
"
,
dev_user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'software_license_policy'
,
dir:
'ee'
)
expect
(
json_response
[
'id'
]).
to
eq
(
software_license_policy
.
id
)
expect
(
json_response
[
'name'
]).
to
eq
(
software_license_policy
.
name
)
expect
(
json_response
[
'approval_status'
]).
to
eq
(
software_license_policy
.
approval_status
)
...
...
@@ -114,6 +118,7 @@ describe API::ManagedLicenses do
get
api
(
"/projects/
#{
project
.
id
}
/managed_licenses/
#{
software_license_policy
.
id
}
"
,
reporter_user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'software_license_policy'
,
dir:
'ee'
)
expect
(
json_response
[
'id'
]).
to
eq
(
software_license_policy
.
id
)
expect
(
json_response
[
'name'
]).
to
eq
(
software_license_policy
.
name
)
expect
(
json_response
[
'approval_status'
]).
to
eq
(
software_license_policy
.
approval_status
)
...
...
@@ -141,6 +146,7 @@ describe API::ManagedLicenses do
end
.
to
change
{
project
.
software_license_policies
.
count
}.
by
(
1
)
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
response
).
to
match_response_schema
(
'software_license_policy'
,
dir:
'ee'
)
expect
(
json_response
).
to
have_key
(
'id'
)
expect
(
json_response
[
'name'
]).
to
eq
(
'NEW_LICENSE_NAME'
)
expect
(
json_response
[
'approval_status'
]).
to
eq
(
'approved'
)
...
...
@@ -209,6 +215,7 @@ describe API::ManagedLicenses do
updated_software_license_policy
=
project
.
software_license_policies
.
reload
.
first
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'software_license_policy'
,
dir:
'ee'
)
# Check that response is equal to the updated object
expect
(
json_response
[
'id'
]).
to
eq
(
initial_id
)
...
...
ee/spec/services/ci/compare_license_management_reports_service_spec.rb
View file @
d6e6b56d
...
...
@@ -6,6 +6,10 @@ describe Ci::CompareLicenseManagementReportsService do
let
(
:service
)
{
described_class
.
new
(
project
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
before
do
stub_licensed_features
(
license_management:
true
)
end
describe
'#execute'
do
subject
{
service
.
execute
(
base_pipeline
,
head_pipeline
)
}
...
...
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