Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a7466af3
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a7466af3
编写于
3月 31, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve code related to removing container image tags
上级
600bbe15
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
36 addition
and
34 deletion
+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
未找到文件。
app/models/container_repository.rb
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
,
{})
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录