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
5896020d
Commit
5896020d
authored
Mar 15, 2021
by
Sofia Vistas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Container Registry API tests
parent
aaee395b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
168 additions
and
7 deletions
+168
-7
qa/qa/resource/registry_repository.rb
qa/qa/resource/registry_repository.rb
+49
-7
qa/qa/specs/features/api/5_package/.gitkeep
qa/qa/specs/features/api/5_package/.gitkeep
+0
-0
qa/qa/specs/features/api/5_package/container_registry_spec.rb
...a/specs/features/api/5_package/container_registry_spec.rb
+119
-0
No files found.
qa/qa/resource/registry_repository.rb
View file @
5896020d
...
@@ -6,7 +6,7 @@ module QA
...
@@ -6,7 +6,7 @@ module QA
module
Resource
module
Resource
class
RegistryRepository
<
Base
class
RegistryRepository
<
Base
attr_accessor
:name
,
attr_accessor
:name
,
:
repository_id
:
tag_name
attribute
:project
do
attribute
:project
do
Project
.
fabricate_via_api!
do
|
resource
|
Project
.
fabricate_via_api!
do
|
resource
|
...
@@ -15,9 +15,17 @@ module QA
...
@@ -15,9 +15,17 @@ module QA
end
end
end
end
attribute
:id
do
registry_repositories
=
project
.
registry_repositories
return
unless
(
this_registry_repository
=
registry_repositories
&
.
find
{
|
registry_repository
|
registry_repository
[
:path
]
==
name
})
# rubocop:disable Cop/AvoidReturnFromBlocks
this_registry_repository
[
:id
]
end
def
initialize
def
initialize
@name
=
project
.
path_with_namespace
@name
=
project
.
path_with_namespace
@
repository_id
=
nil
@
tag_name
=
'master'
end
end
def
fabricate!
def
fabricate!
...
@@ -31,23 +39,57 @@ module QA
...
@@ -31,23 +39,57 @@ module QA
def
remove_via_api!
def
remove_via_api!
registry_repositories
=
project
.
registry_repositories
registry_repositories
=
project
.
registry_repositories
if
registry_repositories
&&
!
registry_repositories
.
empty?
this_registry_repository
=
registry_repositories
.
find
{
|
registry_repository
|
registry_repository
[
:path
]
==
name
}
@repository_id
=
this_registry_repository
[
:id
]
if
registry_repositories
&&
!
registry_repositories
.
empty?
QA
::
Runtime
::
Logger
.
debug
(
"Deleting registry '
#{
name
}
'"
)
QA
::
Runtime
::
Logger
.
debug
(
"Deleting registry '
#{
name
}
'"
)
super
super
end
end
end
end
def
api_delete_path
def
api_delete_path
"/projects/
#{
project
.
id
}
/registry/repositories/
#{
@repository_id
}
"
"/projects/
#{
project
.
id
}
/registry/repositories/
#{
id
}
"
end
def
api_delete_tag_path
"/projects/
#{
project
.
id
}
/registry/repositories/
#{
id
}
/tags/
#{
tag_name
}
"
end
end
def
api_get_path
def
api_get_path
"/projects/
#{
project
.
id
}
/registry/repositories"
"/projects/
#{
project
.
id
}
/registry/repositories"
end
end
def
api_get_tags_path
"/projects/
#{
project
.
id
}
/registry/repositories/
#{
id
}
/tags"
end
def
has_tag?
(
tag_name
)
response
=
get
Runtime
::
API
::
Request
.
new
(
api_client
,
api_get_tags_path
).
url
raise
ResourceNotFoundError
,
"Request returned (
#{
response
.
code
}
): `
#{
response
}
`."
if
response
.
code
==
HTTP_STATUS_NOT_FOUND
tag_list
=
parse_body
(
response
)
tag_list
.
any?
{
|
tag
|
tag
[
:name
]
==
tag_name
}
end
def
has_no_tag?
(
tag_name
)
response
=
get
Runtime
::
API
::
Request
.
new
(
api_client
,
api_get_tags_path
).
url
raise
ResourceNotFoundError
,
"Request returned (
#{
response
.
code
}
): `
#{
response
}
`."
if
response
.
code
==
HTTP_STATUS_NOT_FOUND
tag_list
=
parse_body
(
response
)
tag_list
.
none?
{
|
tag
|
tag
[
:name
]
==
tag_name
}
end
def
delete_tag
QA
::
Runtime
::
Logger
.
debug
(
"Deleting registry tag '
#{
tag_name
}
'"
)
request
=
Runtime
::
API
::
Request
.
new
(
api_client
,
api_delete_tag_path
)
response
=
delete
(
request
.
url
)
unless
[
HTTP_STATUS_NO_CONTENT
,
HTTP_STATUS_ACCEPTED
,
HTTP_STATUS_OK
].
include?
response
.
code
raise
ResourceNotDeletedError
,
"Resource at
#{
request
.
mask_url
}
could not be deleted (
#{
response
.
code
}
): `
#{
response
}
`."
end
end
end
end
end
end
end
end
qa/qa/specs/features/api/5_package/.gitkeep
deleted
100644 → 0
View file @
aaee395b
qa/qa/specs/features/api/5_package/container_registry_spec.rb
0 → 100644
View file @
5896020d
# frozen_string_literal: true
require
'airborne'
module
QA
RSpec
.
describe
'Package'
,
only:
{
subdomain: :staging
}
do
include
Support
::
Api
describe
'Container Registry'
do
let
(
:api_client
)
{
Runtime
::
API
::
Client
.
new
(
:gitlab
)
}
let
(
:project
)
do
Resource
::
Project
.
fabricate_via_api!
do
|
project
|
project
.
name
=
'project-with-registry-api'
project
.
template_name
=
'express'
end
end
let
(
:registry
)
do
Resource
::
RegistryRepository
.
new
.
tap
do
|
repository
|
repository
.
name
=
"
#{
project
.
path_with_namespace
}
"
repository
.
project
=
project
repository
.
tag_name
=
'master'
end
end
let
(
:gitlab_ci_yaml
)
do
<<~
YAML
stages:
- build
- test
build:
image: docker:19.03.12
stage: build
services:
- docker:19.03.12-dind
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $IMAGE_TAG .
- docker push $IMAGE_TAG
- docker pull $IMAGE_TAG
test:
image: dwdraju/alpine-curl-jq:latest
stage: test
variables:
MEDIA_TYPE: 'application/vnd.docker.distribution.manifest.v2+json'
before_script:
- token=$(curl -u "$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD" "https://$CI_SERVER_HOST/jwt/auth?service=container_registry&scope=repository:$CI_PROJECT_PATH:pull,push,delete" | jq -r '.token')
script:
- 'digest=$(curl -L -H "Authorization: Bearer $token" -H "Accept: $MEDIA_TYPE" "https://$CI_REGISTRY/v2/$CI_PROJECT_PATH/manifests/master" | jq -r ".layers[0].digest")'
- 'curl -L -X DELETE -H "Authorization: Bearer $token" -H "Accept: $MEDIA_TYPE" "https://$CI_REGISTRY/v2/$CI_PROJECT_PATH/blobs/$digest"'
- 'curl -L --head -H "Authorization: Bearer $token" -H "Accept: $MEDIA_TYPE" "https://$CI_REGISTRY/v2/$CI_PROJECT_PATH/blobs/$digest"'
- 'digest=$(curl -L -H "Authorization: Bearer $token" -H "Accept: $MEDIA_TYPE" "https://$CI_REGISTRY/v2/$CI_PROJECT_PATH/manifests/master" | jq -r ".config.digest")'
- 'curl -L -X DELETE -H "Authorization: Bearer $token" -H "Accept: $MEDIA_TYPE" "https://$CI_REGISTRY/v2/$CI_PROJECT_PATH/manifests/$digest"'
- 'curl -L --head -H "Authorization: Bearer $token" -H "Accept: $MEDIA_TYPE" "https://$CI_REGISTRY/v2/$CI_PROJECT_PATH/manifests/$digest"'
YAML
end
after
do
registry
&
.
remove_via_api!
end
it
'pushes, pulls image to the registry and deletes image blob, manifest and tag'
,
testcase:
'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1738'
do
Resource
::
Repository
::
Commit
.
fabricate_via_api!
do
|
commit
|
commit
.
project
=
project
commit
.
commit_message
=
'Add .gitlab-ci.yml'
commit
.
add_files
([{
file_path:
'.gitlab-ci.yml'
,
content:
gitlab_ci_yaml
}])
end
Support
::
Waiter
.
wait_until
(
max_duration:
10
)
{
pipeline_is_triggered?
}
Support
::
Retrier
.
retry_until
(
max_duration:
260
,
sleep_interval:
5
)
do
latest_pipeline_succeed?
end
expect
(
job_log
).
to
have_content
'404 Not Found'
expect
(
registry
).
to
have_tag
(
'master'
)
registry
.
delete_tag
expect
(
registry
).
not_to
have_tag
(
'master'
)
end
private
def
pipeline_is_triggered?
!
project
.
pipelines
.
empty?
end
def
latest_pipeline_succeed?
latest_pipeline
=
project
.
pipelines
.
first
latest_pipeline
[
:status
]
==
'success'
end
def
job_log
pipeline
=
project
.
pipelines
.
first
pipeline_id
=
pipeline
[
:id
]
jobs
=
get
Runtime
::
API
::
Request
.
new
(
api_client
,
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline_id
}
/jobs"
).
url
test_job
=
parse_body
(
jobs
).
first
test_job_id
=
test_job
[
:id
]
log
=
get
Runtime
::
API
::
Request
.
new
(
api_client
,
"/projects/
#{
project
.
id
}
/jobs/
#{
test_job_id
}
/trace"
).
url
QA
::
Runtime
::
Logger
.
debug
(
"
\n\n
------- Test job log: -------
\n\n
#{
log
}
\n
-------"
)
log
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