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
f451173a
Commit
f451173a
authored
Mar 23, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix specs for container repository model class
parent
ea16ea5b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
102 deletions
+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
No files found.
app/models/container_repository.rb
View file @
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
deleted
100644 → 0
View file @
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
View file @
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
deleted
100644 → 0
View file @
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
View file @
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
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