Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
f451173a
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 搜索 >>
提交
f451173a
编写于
3月 23, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix specs for container repository model class
上级
ea16ea5b
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
132 addition
and
102 deletion
+132
-102
app/models/container_repository.rb
app/models/container_repository.rb
+14
-7
spec/factories/container_images.rb
spec/factories/container_images.rb
+0
-22
spec/factories/container_repositories.rb
spec/factories/container_repositories.rb
+22
-0
spec/models/container_image_spec.rb
spec/models/container_image_spec.rb
+0
-73
spec/models/container_repository_spec.rb
spec/models/container_repository_spec.rb
+96
-0
未找到文件。
app/models/container_repository.rb
浏览文件 @
f451173a
class
ContainerRepository
<
ActiveRecord
::
Base
belongs_to
:project
delegate
:container_registry
,
to: :project
delegate
:client
,
to: :container_registry
delegate
:client
,
to: :registry
validates
:manifest
,
presence:
true
validates
:name
,
presence:
true
before_destroy
:delete_tags
def
registry
# TODO, container registry with image access level
token
=
Auth
::
ContainerRegistryAuthenticationService
.
image_token
(
self
)
@registry
||=
begin
token
=
Auth
::
ContainerRegistryAuthenticationService
.
full_access_token
(
path
)
url
=
Gitlab
.
config
.
registry
.
api_url
host_port
=
Gitlab
.
config
.
registry
.
host_port
ContainerRegistry
::
Registry
.
new
(
url
,
token:
token
,
path:
host_port
)
end
end
def
path
@path
||=
"
#{
project
.
full_path
}
/
#{
name
}
"
end
def
tag
(
tag
)
...
...
spec/factories/container_images.rb
已删除
100644 → 0
浏览文件 @
ea16ea5b
FactoryGirl
.
define
do
factory
:container_image
do
name
"test_container_image"
project
transient
do
tags
[
'tag'
]
stubbed
true
end
after
(
:build
)
do
|
image
,
evaluator
|
if
evaluator
.
stubbed
allow
(
Gitlab
.
config
.
registry
).
to
receive
(
:enabled
).
and_return
(
true
)
allow
(
Auth
::
ContainerRegistryAuthenticationService
).
to
receive
(
:full_access_token
).
and_return
(
'token'
)
allow
(
image
.
client
).
to
receive
(
:repository_tags
).
and_return
({
name:
image
.
name_with_namespace
,
tags:
evaluator
.
tags
})
end
end
end
end
spec/factories/container_repositories.rb
0 → 100644
浏览文件 @
f451173a
FactoryGirl
.
define
do
factory
:container_repository
do
name
"test_container_image"
project
transient
do
tags
[
'tag'
]
end
after
(
:build
)
do
|
image
,
evaluator
|
# if evaluator.tags.to_a.any?
# allow(Gitlab.config.registry).to receive(:enabled).and_return(true)
# allow(Auth::ContainerRegistryAuthenticationService)
# .to receive(:full_access_token).and_return('token')
# allow(image.client).to receive(:repository_tags).and_return({
# name: image.name_with_namespace,
# tags: evaluator.tags
# })
# end
end
end
end
spec/models/container_image_spec.rb
已删除
100644 → 0
浏览文件 @
ea16ea5b
require
'spec_helper'
describe
ContainerImage
do
let
(
:group
)
{
create
(
:group
,
name:
'group'
)
}
let
(
:project
)
{
create
(
:project
,
path:
'test'
,
group:
group
)
}
let
(
:example_host
)
{
'example.com'
}
let
(
:registry_url
)
{
'http://'
+
example_host
}
let
(
:container_image
)
{
create
(
:container_image
,
name:
''
,
project:
project
,
stubbed:
false
)
}
before
do
stub_container_registry_config
(
enabled:
true
,
api_url:
registry_url
,
host_port:
example_host
)
stub_request
(
:get
,
'http://example.com/v2/group/test/tags/list'
).
with
(
headers:
{
'Accept'
=>
'application/vnd.docker.distribution.manifest.v2+json'
}).
to_return
(
status:
200
,
body:
JSON
.
dump
(
tags:
[
'test'
]),
headers:
{
'Content-Type'
=>
'application/json'
})
end
it
{
expect
(
container_image
).
to
respond_to
(
:project
)
}
it
{
expect
(
container_image
).
to
delegate_method
(
:container_registry
).
to
(
:project
)
}
it
{
expect
(
container_image
).
to
delegate_method
(
:client
).
to
(
:container_registry
)
}
it
{
expect
(
container_image
.
tag
(
'test'
)).
not_to
be_nil
}
context
'#path'
do
subject
{
container_image
.
path
}
it
{
is_expected
.
to
eq
(
'example.com/group/test'
)
}
end
context
'manifest processing'
do
context
'#manifest'
do
subject
{
container_image
.
manifest
}
it
{
is_expected
.
not_to
be_nil
}
end
context
'#valid?'
do
subject
{
container_image
.
valid?
}
it
{
is_expected
.
to
be_truthy
}
end
context
'#tags'
do
subject
{
container_image
.
tags
}
it
{
is_expected
.
not_to
be_empty
}
end
end
context
'#delete_tags'
do
let
(
:tag
)
{
ContainerRegistry
::
Tag
.
new
(
container_image
,
'tag'
)
}
before
do
expect
(
container_image
).
to
receive
(
:tags
).
twice
.
and_return
([
tag
])
expect
(
tag
).
to
receive
(
:digest
).
and_return
(
'sha256:4c8e63ca4cb663ce6c688cb06f1c3672a172b088dac5b6d7ad7d49cd620d85cf'
)
end
subject
{
container_image
.
delete_tags
}
context
'succeeds'
do
before
{
expect
(
container_image
.
client
).
to
receive
(
:delete_repository_tag
).
and_return
(
true
)
}
it
{
is_expected
.
to
be_truthy
}
end
context
'any fails'
do
before
{
expect
(
container_image
.
client
).
to
receive
(
:delete_repository_tag
).
and_return
(
false
)
}
it
{
is_expected
.
to
be_falsey
}
end
end
end
spec/models/container_repository_spec.rb
0 → 100644
浏览文件 @
f451173a
require
'spec_helper'
describe
ContainerRepository
do
let
(
:group
)
{
create
(
:group
,
name:
'group'
)
}
let
(
:project
)
{
create
(
:project
,
path:
'test'
,
group:
group
)
}
let
(
:container_repository
)
do
create
(
:container_repository
,
name:
'my_image'
,
project:
project
)
end
before
do
stub_container_registry_config
(
enabled:
true
,
api_url:
'http://registry.gitlab'
,
host_port:
'registry.gitlab'
)
stub_request
(
:get
,
'http://registry.gitlab/v2/group/test/my_image/tags/list'
)
.
with
(
headers:
{
'Accept'
=>
'application/vnd.docker.distribution.manifest.v2+json'
})
.
to_return
(
status:
200
,
body:
JSON
.
dump
(
tags:
[
'test_tag'
]),
headers:
{
'Content-Type'
=>
'application/json'
})
end
describe
'associations'
do
it
'belongs to the project'
do
expect
(
container_repository
).
to
belong_to
(
:project
)
end
end
describe
'#tag'
do
it
'has a test tag'
do
expect
(
container_repository
.
tag
(
'test'
)).
not_to
be_nil
end
end
describe
'#path'
do
it
'returns a full path to the repository'
do
expect
(
container_repository
.
path
).
to
eq
(
'group/test/my_image'
)
end
end
describe
'#manifest'
do
subject
{
container_repository
.
manifest
}
it
{
is_expected
.
not_to
be_nil
}
end
describe
'#valid?'
do
subject
{
container_repository
.
valid?
}
it
{
is_expected
.
to
be_truthy
}
end
describe
'#tags'
do
subject
{
container_repository
.
tags
}
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'
)
end
context
'when action succeeds'
do
before
do
allow
(
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
end
end
context
'when action fails'
do
before
do
allow
(
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
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录