Commit 91c4002a authored by Kamil Trzcinski's avatar Kamil Trzcinski

Improve test coverage

parent 72a71e9d
...@@ -39,7 +39,7 @@ module ContainerRegistry ...@@ -39,7 +39,7 @@ module ContainerRegistry
def delete_tags def delete_tags
return unless tags return unless tags
tags.each(:delete) tags.all?(&:delete)
end end
def mount_blob(blob) def mount_blob(blob)
......
...@@ -14,7 +14,7 @@ describe "Container Registry" do ...@@ -14,7 +14,7 @@ describe "Container Registry" do
before do before do
login_as(:user) login_as(:user)
project.team << [@user, :developer] project.team << [@user, :developer]
stub_container_registry(*tags) stub_container_registry_tags(*tags)
allow(Gitlab.config.registry).to receive_messages(registry_settings) allow(Gitlab.config.registry).to receive_messages(registry_settings)
allow(Auth::ContainerRegistryAuthenticationService).to receive(:full_access_token).and_return('token') allow(Auth::ContainerRegistryAuthenticationService).to receive(:full_access_token).and_return('token')
end end
......
...@@ -70,6 +70,20 @@ describe Namespace, models: true do ...@@ -70,6 +70,20 @@ describe Namespace, models: true do
allow(@namespace).to receive(:path).and_return(new_path) allow(@namespace).to receive(:path).and_return(new_path)
expect(@namespace.move_dir).to be_truthy expect(@namespace.move_dir).to be_truthy
end end
context "when any project has container tags" do
before do
stub_container_registry_config(enabled: true)
stub_container_registry_tags('tag')
create(:empty_project, namespace: @namespace)
allow(@namespace).to receive(:path_was).and_return(@namespace.path)
allow(@namespace).to receive(:path).and_return('new_path')
end
it { expect { @namespace.move_dir }.to raise_error('Namespace cannot be moved, because at least one project has tags in container registry') }
end
end end
describe :rm_dir do describe :rm_dir do
......
...@@ -634,11 +634,11 @@ describe Project, models: true do ...@@ -634,11 +634,11 @@ describe Project, models: true do
# Project#gitlab_shell returns a new instance of Gitlab::Shell on every # Project#gitlab_shell returns a new instance of Gitlab::Shell on every
# call. This makes testing a bit easier. # call. This makes testing a bit easier.
allow(project).to receive(:gitlab_shell).and_return(gitlab_shell) allow(project).to receive(:gitlab_shell).and_return(gitlab_shell)
end
it 'renames a repository' do
allow(project).to receive(:previous_changes).and_return('path' => ['foo']) allow(project).to receive(:previous_changes).and_return('path' => ['foo'])
end
it 'renames a repository' do
ns = project.namespace_dir ns = project.namespace_dir
expect(gitlab_shell).to receive(:mv_repository). expect(gitlab_shell).to receive(:mv_repository).
...@@ -663,6 +663,17 @@ describe Project, models: true do ...@@ -663,6 +663,17 @@ describe Project, models: true do
project.rename_repo project.rename_repo
end end
context 'container registry with tags' do
before do
stub_container_registry_config(enabled: true)
stub_container_registry_tags('tag')
end
subject { project.rename_repo }
it { expect{subject}.to raise_error(Exception) }
end
end end
describe '#expire_caches_before_rename' do describe '#expire_caches_before_rename' do
...@@ -825,13 +836,13 @@ describe Project, models: true do ...@@ -825,13 +836,13 @@ describe Project, models: true do
end end
context 'with tags' do context 'with tags' do
before { stub_container_registry('test', 'test2') } before { stub_container_registry_tags('test', 'test2') }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
context 'when no tags' do context 'when no tags' do
before { stub_container_registry } before { stub_container_registry_tags }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
......
...@@ -28,6 +28,35 @@ describe Projects::DestroyService, services: true do ...@@ -28,6 +28,35 @@ describe Projects::DestroyService, services: true do
it { expect(Dir.exist?(remove_path)).to be_truthy } it { expect(Dir.exist?(remove_path)).to be_truthy }
end end
context 'container registry' do
let(:registry_settings) do
{
enabled: true
}
end
before do
allow(Gitlab.config.registry).to receive_messages(registry_settings)
stub_container_registry_tags('tag')
end
context 'tags deletion succeeds' do
it do
expect_any_instance_of(ContainerRegistry::Tag).to receive(:delete).and_return(true)
destroy_project(project, user, {})
end
end
context 'tags deletion fails' do
before { expect_any_instance_of(ContainerRegistry::Tag).to receive(:delete).and_return(false) }
subject { destroy_project(project, user, {}) }
it { expect{subject}.to raise_error(Projects::DestroyService::DestroyError) }
end
end
def destroy_project(project, user, params) def destroy_project(project, user, params)
Projects::DestroyService.new(project, user, params).execute Projects::DestroyService.new(project, user, params).execute
end end
......
...@@ -26,6 +26,17 @@ describe Projects::TransferService, services: true do ...@@ -26,6 +26,17 @@ describe Projects::TransferService, services: true do
it { expect(project.namespace).to eq(user.namespace) } it { expect(project.namespace).to eq(user.namespace) }
end end
context 'disallow transfering of project with tags' do
before do
stub_container_registry_config(enabled: true)
stub_container_registry_tags('tag')
end
subject { transfer_project(project, user, group) }
it { is_expected.to be_falsey }
end
context 'namespace -> not allowed namespace' do context 'namespace -> not allowed namespace' do
before do before do
@result = transfer_project(project, user, group) @result = transfer_project(project, user, group)
......
...@@ -25,7 +25,11 @@ module StubGitlabCalls ...@@ -25,7 +25,11 @@ module StubGitlabCalls
allow_any_instance_of(Project).to receive(:builds_enabled?).and_return(false) allow_any_instance_of(Project).to receive(:builds_enabled?).and_return(false)
end end
def stub_container_registry(*tags) def stub_container_registry_config(registry_settings)
allow(Gitlab.config.registry).to receive_messages(registry_settings)
end
def stub_container_registry_tags(*tags)
allow_any_instance_of(ContainerRegistry::Client).to receive(:repository_tags).and_return( allow_any_instance_of(ContainerRegistry::Client).to receive(:repository_tags).and_return(
{ "tags" => tags } { "tags" => tags }
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment