Fix specs for services related to container registry
This commit is contained in:
parent
af42dd29a0
commit
7db1f22673
3 changed files with 33 additions and 25 deletions
|
@ -1,34 +1,42 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe ContainerImages::DestroyService, services: true do
|
describe ContainerImages::DestroyService, '#execute', :services do
|
||||||
describe '#execute' do
|
let(:user) { create(:user) }
|
||||||
let(:user) { create(:user) }
|
|
||||||
let(:container_repository) { create(:container_repository, name: '') }
|
|
||||||
let(:project) { create(:project, path: 'test', namespace: user.namespace, container_repositorys: [container_repository]) }
|
|
||||||
let(:example_host) { 'example.com' }
|
|
||||||
let(:registry_url) { 'http://' + example_host }
|
|
||||||
|
|
||||||
it { expect(container_repository).to be_valid }
|
let(:container_repository) do
|
||||||
it { expect(project.container_repositorys).not_to be_empty }
|
create(:container_repository, name: 'myimage', tags: %w[latest])
|
||||||
|
end
|
||||||
|
|
||||||
context 'when container image has tags' do
|
let(:project) do
|
||||||
before do
|
create(:project, path: 'test',
|
||||||
project.team << [user, :master]
|
namespace: user.namespace,
|
||||||
end
|
container_repositories: [container_repository])
|
||||||
|
end
|
||||||
|
|
||||||
it 'removes all tags before destroy' do
|
it { expect(container_repository).to be_valid }
|
||||||
service = described_class.new(project, user)
|
it { expect(project.container_repositories).not_to be_empty }
|
||||||
|
|
||||||
expect(container_repository).to receive(:delete_tags).and_return(true)
|
context 'when container image has tags' do
|
||||||
expect { service.execute(container_repository) }.to change(project.container_repositorys, :count).by(-1)
|
before do
|
||||||
end
|
project.add_master(user)
|
||||||
|
end
|
||||||
|
|
||||||
it 'fails when tags are not removed' do
|
it 'removes all tags before destroy' do
|
||||||
service = described_class.new(project, user)
|
service = described_class.new(project, user)
|
||||||
|
|
||||||
expect(container_repository).to receive(:delete_tags).and_return(false)
|
expect(container_repository)
|
||||||
expect { service.execute(container_repository) }.to raise_error(ActiveRecord::RecordNotDestroyed)
|
.to receive(:delete_tags).and_return(true)
|
||||||
end
|
expect { service.execute(container_repository) }
|
||||||
|
.to change(project.container_repositories, :count).by(-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'fails when tags are not removed' do
|
||||||
|
service = described_class.new(project, user)
|
||||||
|
|
||||||
|
expect(container_repository)
|
||||||
|
.to receive(:delete_tags).and_return(false)
|
||||||
|
expect { service.execute(container_repository) }
|
||||||
|
.to raise_error(ActiveRecord::RecordNotDestroyed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -95,7 +95,7 @@ describe Projects::DestroyService, services: true do
|
||||||
before do
|
before do
|
||||||
stub_container_registry_config(enabled: true)
|
stub_container_registry_config(enabled: true)
|
||||||
stub_container_registry_tags('tag')
|
stub_container_registry_tags('tag')
|
||||||
project.container_repositorys << container_repository
|
project.container_repositories << container_repository
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'images deletion succeeds' do
|
context 'images deletion succeeds' do
|
||||||
|
|
|
@ -34,7 +34,7 @@ describe Projects::TransferService, services: true do
|
||||||
before do
|
before do
|
||||||
stub_container_registry_config(enabled: true)
|
stub_container_registry_config(enabled: true)
|
||||||
stub_container_registry_tags('tag')
|
stub_container_registry_tags('tag')
|
||||||
project.container_repositorys << container_repository
|
project.container_repositories << container_repository
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { transfer_project(project, user, group) }
|
subject { transfer_project(project, user, group) }
|
||||||
|
|
Loading…
Reference in a new issue