2017-03-28 08:34:56 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ContainerRegistry::Path do
|
2017-03-29 06:53:02 -04:00
|
|
|
subject { described_class.new(path) }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
2017-04-04 05:56:32 -04:00
|
|
|
describe '#components' do
|
2017-04-03 05:42:37 -04:00
|
|
|
let(:path) { 'path/to/some/project' }
|
|
|
|
|
2017-04-04 05:56:32 -04:00
|
|
|
it 'splits components by a forward slash' do
|
|
|
|
expect(subject.components).to eq %w[path to some project]
|
2017-04-03 05:42:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-04 05:56:32 -04:00
|
|
|
describe '#nodes' do
|
2017-03-28 08:34:56 -04:00
|
|
|
context 'when repository path is valid' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { 'path/to/some/project' }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
2017-04-04 05:56:32 -04:00
|
|
|
it 'return all project path like node in reverse order' do
|
|
|
|
expect(subject.nodes).to eq %w[path/to/some/project
|
|
|
|
path/to/some
|
|
|
|
path/to]
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository path is invalid' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { '' }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
|
|
|
it 'rasises en error' do
|
2017-04-04 05:56:32 -04:00
|
|
|
expect { subject.nodes }
|
2017-03-28 08:34:56 -04:00
|
|
|
.to raise_error described_class::InvalidRegistryPathError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-29 06:53:02 -04:00
|
|
|
describe '#to_s' do
|
2017-04-13 03:20:42 -04:00
|
|
|
context 'when path does not have uppercase characters' do
|
|
|
|
let(:path) { 'some/image' }
|
2017-03-29 06:53:02 -04:00
|
|
|
|
2017-04-13 03:20:42 -04:00
|
|
|
it 'return a string with a repository path' do
|
|
|
|
expect(subject.to_s).to eq 'some/image'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when path has uppercase characters' do
|
|
|
|
let(:path) { 'SoMe/ImAgE' }
|
|
|
|
|
|
|
|
it 'return a string with a repository path' do
|
|
|
|
expect(subject.to_s).to eq 'some/image'
|
|
|
|
end
|
2017-03-29 06:53:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-28 08:34:56 -04:00
|
|
|
describe '#valid?' do
|
|
|
|
context 'when path has less than two components' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { 'something/' }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
2017-04-03 05:38:39 -04:00
|
|
|
it { is_expected.not_to be_valid }
|
2017-03-31 05:12:38 -04:00
|
|
|
end
|
2017-03-28 08:34:56 -04:00
|
|
|
|
|
|
|
context 'when path has more than allowed number of components' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { 'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/r/s/t/u/w/y/z' }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
2017-04-03 05:38:39 -04:00
|
|
|
it { is_expected.not_to be_valid }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when path has invalid characters' do
|
|
|
|
let(:path) { 'some\path' }
|
|
|
|
|
|
|
|
it { is_expected.not_to be_valid }
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when path has two or more components' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { 'some/path' }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
2017-04-03 05:38:39 -04:00
|
|
|
it { is_expected.to be_valid }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when path is related to multi-level image' do
|
|
|
|
let(:path) { 'some/path/my/image' }
|
|
|
|
|
|
|
|
it { is_expected.to be_valid }
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|
2017-04-13 03:20:42 -04:00
|
|
|
|
|
|
|
context 'when path contains uppercase letters' do
|
|
|
|
let(:path) { 'Some/Registry' }
|
|
|
|
|
|
|
|
it { is_expected.to be_valid }
|
|
|
|
end
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|
|
|
|
|
2017-03-30 07:45:54 -04:00
|
|
|
describe '#has_repository?' do
|
|
|
|
context 'when project exists' do
|
|
|
|
let(:project) { create(:empty_project) }
|
|
|
|
let(:path) { "#{project.full_path}/my/image" }
|
|
|
|
|
|
|
|
context 'when path already has matching repository' do
|
|
|
|
before do
|
|
|
|
create(:container_repository, project: project, name: 'my/image')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to have_repository }
|
|
|
|
it { is_expected.to have_project }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when path does not have matching repository' do
|
|
|
|
it { is_expected.not_to have_repository }
|
|
|
|
it { is_expected.to have_project }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project does not exist' do
|
|
|
|
let(:path) { 'some/project/my/image' }
|
|
|
|
|
|
|
|
it { is_expected.not_to have_repository }
|
|
|
|
it { is_expected.not_to have_project }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-28 08:34:56 -04:00
|
|
|
describe '#repository_project' do
|
|
|
|
let(:group) { create(:group, path: 'some_group') }
|
|
|
|
|
|
|
|
context 'when project for given path exists' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { 'some_group/some_project' }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
create(:empty_project, group: group, name: 'some_project')
|
|
|
|
create(:empty_project, name: 'some_project')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a correct project' do
|
2017-03-29 06:53:02 -04:00
|
|
|
expect(subject.repository_project.group).to eq group
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project for given path does not exist' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { 'not/matching' }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
|
|
|
it 'returns nil' do
|
2017-03-29 06:53:02 -04:00
|
|
|
expect(subject.repository_project).to be_nil
|
2017-03-28 08:34:56 -04:00
|
|
|
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
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { project.full_path }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
|
|
|
it 'supports zero-level path' do
|
2017-03-29 06:53:02 -04:00
|
|
|
expect(subject.repository_project).to eq project
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using first-level path' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { "#{project.full_path}/repository" }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
|
|
|
it 'supports first-level path' do
|
2017-03-29 06:53:02 -04:00
|
|
|
expect(subject.repository_project).to eq project
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using second-level path' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { "#{project.full_path}/repository/name" }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
|
|
|
it 'supports second-level path' do
|
2017-03-29 06:53:02 -04:00
|
|
|
expect(subject.repository_project).to eq project
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using too deep nesting in the path' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { "#{project.full_path}/repository/name/invalid" }
|
2017-03-28 08:34:56 -04:00
|
|
|
|
|
|
|
it 'does not support three-levels of nesting' do
|
2017-03-29 06:53:02 -04:00
|
|
|
expect(subject.repository_project).to be_nil
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#repository_name' do
|
2017-03-28 08:57:22 -04:00
|
|
|
context 'when project does not exist' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { 'some/name' }
|
2017-03-28 08:57:22 -04:00
|
|
|
|
|
|
|
it 'returns nil' do
|
2017-03-29 06:53:02 -04:00
|
|
|
expect(subject.repository_name).to be_nil
|
2017-03-28 08:57:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project exists' do
|
2017-04-18 16:20:47 -04:00
|
|
|
let(:group) { create(:group, path: 'Some_Group') }
|
2017-03-28 08:57:22 -04:00
|
|
|
|
|
|
|
before do
|
2017-04-19 02:59:05 -04:00
|
|
|
create(:empty_project, group: group, name: 'some_project')
|
2017-03-28 08:57:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project path equal repository path' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { 'some_group/some_project' }
|
2017-03-28 08:57:22 -04:00
|
|
|
|
|
|
|
it 'returns an empty string' do
|
2017-03-29 06:53:02 -04:00
|
|
|
expect(subject.repository_name).to eq ''
|
2017-03-28 08:57:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository path has one additional level' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { 'some_group/some_project/repository' }
|
2017-03-28 08:57:22 -04:00
|
|
|
|
|
|
|
it 'returns a correct repository name' do
|
2017-03-29 06:53:02 -04:00
|
|
|
expect(subject.repository_name).to eq 'repository'
|
2017-03-28 08:57:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository path has two additional levels' do
|
2017-03-29 06:53:02 -04:00
|
|
|
let(:path) { 'some_group/some_project/repository/image' }
|
2017-03-28 08:57:22 -04:00
|
|
|
|
|
|
|
it 'returns a correct repository name' do
|
2017-03-29 06:53:02 -04:00
|
|
|
expect(subject.repository_name).to eq 'repository/image'
|
2017-03-28 08:57:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|
2017-04-18 16:20:47 -04:00
|
|
|
|
|
|
|
describe '#project_path' do
|
|
|
|
context 'when project does not exist' do
|
|
|
|
let(:path) { 'some/name' }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(subject.project_path).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project with uppercase characters in path exists' do
|
2017-04-19 02:59:05 -04:00
|
|
|
let(:path) { 'somegroup/myproject/my/image' }
|
2017-04-18 16:20:47 -04:00
|
|
|
let(:group) { create(:group, path: 'SomeGroup') }
|
|
|
|
|
|
|
|
before do
|
2017-04-19 02:59:05 -04:00
|
|
|
create(:empty_project, group: group, name: 'MyProject')
|
2017-04-18 16:20:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns downcased project path' do
|
2017-04-19 02:59:05 -04:00
|
|
|
expect(subject.project_path).to eq 'somegroup/myproject'
|
2017-04-18 16:20:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-28 08:34:56 -04:00
|
|
|
end
|