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
b15d9042
Commit
b15d9042
authored
Mar 28, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement container repository path class
parent
f09e3fe8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
148 additions
and
0 deletions
+148
-0
lib/container_registry/path.rb
lib/container_registry/path.rb
+29
-0
spec/lib/container_registry/path_spec.rb
spec/lib/container_registry/path_spec.rb
+119
-0
No files found.
lib/container_registry/path.rb
0 → 100644
View file @
b15d9042
module
ContainerRegistry
class
Path
InvalidRegistryPathError
=
Class
.
new
(
StandardError
)
def
initialize
(
name
)
@nodes
=
name
.
to_s
.
split
(
'/'
)
end
def
valid?
@nodes
.
size
>
1
&&
@nodes
.
size
<
Namespace
::
NUMBER_OF_ANCESTORS_ALLOWED
end
def
components
raise
InvalidRegistryPathError
unless
valid?
@components
||=
@nodes
.
size
.
downto
(
2
).
map
do
|
length
|
@nodes
.
take
(
length
).
join
(
'/'
)
end
end
def
repository_project
@project
||=
Project
.
where_full_path_in
(
components
.
first
(
3
))
&
.
first
end
def
repository_name
end
end
end
spec/lib/container_registry/path_spec.rb
0 → 100644
View file @
b15d9042
require
'spec_helper'
describe
ContainerRegistry
::
Path
do
let
(
:path
)
{
described_class
.
new
(
name
)
}
describe
'#components'
do
context
'when repository path is valid'
do
let
(
:name
)
{
'path/to/some/project'
}
it
'return all project-like components in reverse order'
do
expect
(
path
.
components
).
to
eq
%w[path/to/some/project
path/to/some
path/to]
end
end
context
'when repository path is invalid'
do
let
(
:name
)
{
''
}
it
'rasises en error'
do
expect
{
path
.
components
}
.
to
raise_error
described_class
::
InvalidRegistryPathError
end
end
end
describe
'#valid?'
do
context
'when path has less than two components'
do
let
(
:name
)
{
'something/'
}
it
'is not valid'
do
expect
(
path
).
not_to
be_valid
end
end
context
'when path has more than allowed number of components'
do
let
(
:name
)
{
'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/r/s/t/u/w/y/z'
}
it
'is not valid'
do
expect
(
path
).
not_to
be_valid
end
end
context
'when path has two or more components'
do
let
(
:name
)
{
'some/path'
}
it
'is valid'
do
expect
(
path
).
to
be_valid
end
end
end
describe
'#repository_project'
do
let
(
:group
)
{
create
(
:group
,
path:
'some_group'
)
}
context
'when project for given path exists'
do
let
(
:name
)
{
'some_group/some_project'
}
before
do
create
(
:empty_project
,
group:
group
,
name:
'some_project'
)
create
(
:empty_project
,
name:
'some_project'
)
end
it
'returns a correct project'
do
expect
(
path
.
repository_project
.
group
).
to
eq
group
end
end
context
'when project for given path does not exist'
do
let
(
:name
)
{
'not/matching'
}
it
'returns nil'
do
expect
(
path
.
repository_project
).
to
be_nil
end
end
context
'when matching multi-level path'
do
let
(
:project
)
do
create
(
:empty_project
,
group:
group
,
name:
'some_project'
)
end
context
'when using the zero-level path'
do
let
(
:name
)
{
project
.
full_path
}
it
'supports zero-level path'
do
expect
(
path
.
repository_project
).
to
eq
project
end
end
context
'when using first-level path'
do
let
(
:name
)
{
"
#{
project
.
full_path
}
/repository"
}
it
'supports first-level path'
do
expect
(
path
.
repository_project
).
to
eq
project
end
end
context
'when using second-level path'
do
let
(
:name
)
{
"
#{
project
.
full_path
}
/repository/name"
}
it
'supports second-level path'
do
expect
(
path
.
repository_project
).
to
eq
project
end
end
context
'when using too deep nesting in the path'
do
let
(
:name
)
{
"
#{
project
.
full_path
}
/repository/name/invalid"
}
it
'does not support three-levels of nesting'
do
expect
(
path
.
repository_project
).
to
be_nil
end
end
end
end
describe
'#repository_name'
do
pending
'returns a correct name'
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