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
Boxiang Sun
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
Hide 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
...
@@ -45,15 +45,14 @@ class ContainerRepository < ActiveRecord::Base
# TODO, specs needed
# TODO, specs needed
#
#
def
has_tags?
def
has_tags?
tags
.
any?
tags
.
to_a
.
any?
end
end
# TODO, add bang to this method
def
delete_tags!
#
return
unless
has_tags?
def
delete_tags
return
unless
tags
digests
=
tags
.
map
{
|
tag
|
tag
.
digest
}.
to_set
digests
=
tags
.
map
{
|
tag
|
tag
.
digest
}.
to_set
digests
.
all?
do
|
digest
|
digests
.
all?
do
|
digest
|
client
.
delete_repository_tag
(
self
.
path
,
digest
)
client
.
delete_repository_tag
(
self
.
path
,
digest
)
end
end
...
...
spec/factories/container_repositories.rb
View file @
a7466af3
...
@@ -8,13 +8,21 @@ FactoryGirl.define do
...
@@ -8,13 +8,21 @@ FactoryGirl.define do
end
end
after
(
:build
)
do
|
repository
,
evaluator
|
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
})
evaluator
.
tags
.
each
do
|
tag
|
allow
(
repository
.
client
)
allow
(
repository
.
client
)
.
to
receive
(
:repository_tags
)
.
to
receive
(
:repository_tag_digest
)
.
and_return
({
.
with
(
repository
.
path
,
tag
)
name:
repository
.
path
,
.
and_return
(
'sha256:4c8e63ca4cb663ce6c688cb06f1c3'
\
tags:
evaluator
.
tags
'72b088dac5b6d7ad7d49cd620d85cf72a15'
)
})
end
end
end
end
end
end
...
...
spec/features/container_registry_spec.rb
View file @
a7466af3
...
@@ -38,7 +38,8 @@ describe "Container Registry" do
...
@@ -38,7 +38,8 @@ describe "Container Registry" do
end
end
it
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
)
click_on
'Remove image'
click_on
'Remove image'
end
end
...
...
spec/models/container_repository_spec.rb
View file @
a7466af3
...
@@ -57,38 +57,30 @@ describe ContainerRepository do
...
@@ -57,38 +57,30 @@ describe ContainerRepository do
it
{
is_expected
.
not_to
be_empty
}
it
{
is_expected
.
not_to
be_empty
}
end
end
# TODO, improve these specs
describe
'#delete_tags!'
do
#
let
(
:container_repository
)
do
describe
'#delete_tags'
do
create
(
:container_repository
,
name:
'my_image'
,
let
(
:tag
)
{
ContainerRegistry
::
Tag
.
new
(
container_repository
,
'tag'
)
}
tags:
%w[latest rc1]
,
project:
project
)
before
do
allow
(
container_repository
).
to
receive
(
:tags
).
twice
.
and_return
([
tag
])
allow
(
tag
).
to
receive
(
:digest
)
.
and_return
(
'sha256:4c8e63ca4cb663ce6c688cb06f1c3672a172b088dac5b6d7ad7d49cd620d85cf'
)
end
end
context
'when action succeeds'
do
context
'when action succeeds'
do
before
do
it
'returns status that indicates success'
do
allow
(
container_repository
.
client
)
expect
(
container_repository
.
client
)
.
to
receive
(
:delete_repository_tag
)
.
to
receive
(
:delete_repository_tag
)
.
and_return
(
true
)
.
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
end
end
context
'when action fails'
do
context
'when action fails'
do
before
do
it
'returns status that indicates failure'
do
allow
(
container_repository
.
client
)
expect
(
container_repository
.
client
)
.
to
receive
(
:delete_repository_tag
)
.
to
receive
(
:delete_repository_tag
)
.
and_return
(
false
)
.
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
end
end
end
...
...
spec/services/projects/destroy_service_spec.rb
View file @
a7466af3
...
@@ -100,7 +100,8 @@ describe Projects::DestroyService, services: true do
...
@@ -100,7 +100,8 @@ describe Projects::DestroyService, services: true do
context
'images deletion succeeds'
do
context
'images deletion succeeds'
do
it
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
,
{})
destroy_project
(
project
,
user
,
{})
end
end
...
@@ -108,7 +109,8 @@ describe Projects::DestroyService, services: true do
...
@@ -108,7 +109,8 @@ describe Projects::DestroyService, services: true do
context
'images deletion fails'
do
context
'images deletion fails'
do
before
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
end
subject
{
destroy_project
(
project
,
user
,
{})
}
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