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
Jérome Perrin
gitlab-ce
Commits
a7466af3
Commit
a7466af3
authored
Mar 31, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve code related to removing container image tags
parent
600bbe15
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
34 deletions
+36
-34
app/models/container_repository.rb
app/models/container_repository.rb
+5
-6
spec/factories/container_repositories.rb
spec/factories/container_repositories.rb
+14
-6
spec/features/container_registry_spec.rb
spec/features/container_registry_spec.rb
+2
-1
spec/models/container_repository_spec.rb
spec/models/container_repository_spec.rb
+11
-19
spec/services/projects/destroy_service_spec.rb
spec/services/projects/destroy_service_spec.rb
+4
-2
No files found.
app/models/container_repository.rb
View file @
a7466af3
...
...
@@ -45,15 +45,14 @@ class ContainerRepository < ActiveRecord::Base
# TODO, specs needed
#
def
has_tags?
tags
.
any?
tags
.
to_a
.
any?
end
# TODO, add bang to this method
#
def
delete_tags
return
unless
tags
def
delete_tags!
return
unless
has_tags?
digests
=
tags
.
map
{
|
tag
|
tag
.
digest
}.
to_set
digests
=
tags
.
map
{
|
tag
|
tag
.
digest
}.
to_set
digests
.
all?
do
|
digest
|
client
.
delete_repository_tag
(
self
.
path
,
digest
)
end
...
...
spec/factories/container_repositories.rb
View file @
a7466af3
...
...
@@ -8,13 +8,21 @@ FactoryGirl.define do
end
after
(
:build
)
do
|
repository
,
evaluator
|
if
evaluator
.
tags
.
any?
next
if
evaluator
.
tags
.
to_a
.
none?
allow
(
repository
.
client
)
.
to
receive
(
:repository_tags
)
.
and_return
({
name:
repository
.
path
,
tags:
evaluator
.
tags
'name'
=>
repository
.
path
,
'tags'
=>
evaluator
.
tags
})
evaluator
.
tags
.
each
do
|
tag
|
allow
(
repository
.
client
)
.
to
receive
(
:repository_tag_digest
)
.
with
(
repository
.
path
,
tag
)
.
and_return
(
'sha256:4c8e63ca4cb663ce6c688cb06f1c3'
\
'72b088dac5b6d7ad7d49cd620d85cf72a15'
)
end
end
end
...
...
spec/features/container_registry_spec.rb
View file @
a7466af3
...
...
@@ -38,7 +38,8 @@ describe "Container Registry" do
end
it
do
expect_any_instance_of
(
ContainerRepository
).
to
receive
(
:delete_tags
).
and_return
(
true
)
expect_any_instance_of
(
ContainerRepository
)
.
to
receive
(
:delete_tags!
).
and_return
(
true
)
click_on
'Remove image'
end
...
...
spec/models/container_repository_spec.rb
View file @
a7466af3
...
...
@@ -57,38 +57,30 @@ describe ContainerRepository do
it
{
is_expected
.
not_to
be_empty
}
end
# TODO, improve these specs
#
describe
'#delete_tags'
do
let
(
:tag
)
{
ContainerRegistry
::
Tag
.
new
(
container_repository
,
'tag'
)
}
before
do
allow
(
container_repository
).
to
receive
(
:tags
).
twice
.
and_return
([
tag
])
allow
(
tag
).
to
receive
(
:digest
)
.
and_return
(
'sha256:4c8e63ca4cb663ce6c688cb06f1c3672a172b088dac5b6d7ad7d49cd620d85cf'
)
describe
'#delete_tags!'
do
let
(
:container_repository
)
do
create
(
:container_repository
,
name:
'my_image'
,
tags:
%w[latest rc1]
,
project:
project
)
end
context
'when action succeeds'
do
before
do
allow
(
container_repository
.
client
)
it
'returns status that indicates success'
do
expect
(
container_repository
.
client
)
.
to
receive
(
:delete_repository_tag
)
.
and_return
(
true
)
end
it
'returns status that indicates success'
do
expect
(
container_repository
.
delete_tags
).
to
be_truthy
expect
(
container_repository
.
delete_tags!
).
to
be_truthy
end
end
context
'when action fails'
do
before
do
allow
(
container_repository
.
client
)
it
'returns status that indicates failure'
do
expect
(
container_repository
.
client
)
.
to
receive
(
:delete_repository_tag
)
.
and_return
(
false
)
end
it
'returns status that indicates failure'
do
expect
(
container_repository
.
delete_tags
).
to
be_falsey
expect
(
container_repository
.
delete_tags!
).
to
be_falsey
end
end
end
...
...
spec/services/projects/destroy_service_spec.rb
View file @
a7466af3
...
...
@@ -100,7 +100,8 @@ describe Projects::DestroyService, services: true do
context
'images deletion succeeds'
do
it
do
expect_any_instance_of
(
ContainerRepository
).
to
receive
(
:delete_tags
).
and_return
(
true
)
expect_any_instance_of
(
ContainerRepository
)
.
to
receive
(
:delete_tags!
).
and_return
(
true
)
destroy_project
(
project
,
user
,
{})
end
...
...
@@ -108,7 +109,8 @@ describe Projects::DestroyService, services: true do
context
'images deletion fails'
do
before
do
expect_any_instance_of
(
ContainerRepository
).
to
receive
(
:delete_tags
).
and_return
(
false
)
expect_any_instance_of
(
ContainerRepository
)
.
to
receive
(
:delete_tags!
).
and_return
(
false
)
end
subject
{
destroy_project
(
project
,
user
,
{})
}
...
...
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