Skip to content
Snippets Groups Projects
Commit 91c4002a authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Improve test coverage

parent 72a71e9d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -39,7 +39,7 @@ module ContainerRegistry
def delete_tags
return unless tags
 
tags.each(:delete)
tags.all?(&:delete)
end
 
def mount_blob(blob)
Loading
Loading
Loading
Loading
@@ -14,7 +14,7 @@ describe "Container Registry" do
before do
login_as(:user)
project.team << [@user, :developer]
stub_container_registry(*tags)
stub_container_registry_tags(*tags)
allow(Gitlab.config.registry).to receive_messages(registry_settings)
allow(Auth::ContainerRegistryAuthenticationService).to receive(:full_access_token).and_return('token')
end
Loading
Loading
Loading
Loading
@@ -70,6 +70,20 @@ describe Namespace, models: true do
allow(@namespace).to receive(:path).and_return(new_path)
expect(@namespace.move_dir).to be_truthy
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
 
describe :rm_dir do
Loading
Loading
Loading
Loading
@@ -634,11 +634,11 @@ describe Project, models: true do
# Project#gitlab_shell returns a new instance of Gitlab::Shell on every
# call. This makes testing a bit easier.
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'])
end
 
it 'renames a repository' do
ns = project.namespace_dir
 
expect(gitlab_shell).to receive(:mv_repository).
Loading
Loading
@@ -663,6 +663,17 @@ describe Project, models: true do
 
project.rename_repo
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
 
describe '#expire_caches_before_rename' do
Loading
Loading
@@ -825,13 +836,13 @@ describe Project, models: true do
end
 
context 'with tags' do
before { stub_container_registry('test', 'test2') }
before { stub_container_registry_tags('test', 'test2') }
 
it { is_expected.to be_truthy }
end
 
context 'when no tags' do
before { stub_container_registry }
before { stub_container_registry_tags }
 
it { is_expected.to be_falsey }
end
Loading
Loading
Loading
Loading
@@ -28,6 +28,35 @@ describe Projects::DestroyService, services: true do
it { expect(Dir.exist?(remove_path)).to be_truthy }
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)
Projects::DestroyService.new(project, user, params).execute
end
Loading
Loading
Loading
Loading
@@ -26,6 +26,17 @@ describe Projects::TransferService, services: true do
it { expect(project.namespace).to eq(user.namespace) }
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
before do
@result = transfer_project(project, user, group)
Loading
Loading
Loading
Loading
@@ -25,7 +25,11 @@ module StubGitlabCalls
allow_any_instance_of(Project).to receive(:builds_enabled?).and_return(false)
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(
{ "tags" => tags }
)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment