2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'Container Registry', :js, feature_category: :projects do
|
2021-02-22 17:27:13 +05:30
|
|
|
include_context 'container registry tags'
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
let(:container_repository) do
|
|
|
|
create(:container_repository, name: 'my/image')
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
let(:nameless_container_repository) do
|
|
|
|
create(:container_repository, name: '')
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.add_developer(user)
|
|
|
|
stub_container_registry_config(enabled: true)
|
2021-11-18 22:05:49 +05:30
|
|
|
stub_container_registry_info
|
2020-04-08 14:13:33 +05:30
|
|
|
stub_container_registry_tags(repository: :any, tags: [])
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'has a page title set' do
|
|
|
|
visit_container_registry
|
|
|
|
|
|
|
|
expect(page).to have_title _('Container Registry')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are no image repositories' do
|
|
|
|
it 'list page has no container title' do
|
|
|
|
visit_container_registry
|
|
|
|
|
|
|
|
expect(page).to have_content _('There are no container images stored for this project')
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it 'list page has cli commands' do
|
2020-04-08 14:13:33 +05:30
|
|
|
visit_container_registry
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(page).to have_content _('CLI Commands')
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are image repositories' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(repository: %r{my/image}, tags: %w[latest], with_manifest: true)
|
|
|
|
project.container_repositories << container_repository
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'list page has a list of images' do
|
|
|
|
visit_container_registry
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(page).to have_content 'my/image'
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
it 'user removes entire container repository' do
|
2020-04-22 19:07:51 +05:30
|
|
|
visit_container_registry
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
expect_any_instance_of(ContainerRepository).to receive(:delete_scheduled!).and_call_original
|
|
|
|
expect(DeleteContainerRepositoryWorker).not_to receive(:perform_async)
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
find('[title="Remove repository"]').click
|
|
|
|
expect(find('.modal .modal-title')).to have_content _('Remove repository')
|
|
|
|
find('.modal .modal-footer .btn-danger').click
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'navigates to repo details' do
|
|
|
|
visit_container_registry_details('my/image')
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(page).to have_content 'latest'
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
describe 'image repo details' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(repository: %r{my/image}, tags: ('1'..'20').to_a, with_manifest: true)
|
|
|
|
visit_container_registry_details 'my/image'
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'shows the details breadcrumb' do
|
|
|
|
expect(find('.breadcrumbs')).to have_link 'my/image'
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'shows the image title' do
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(page).to have_content 'my/image'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the image tags' do
|
2022-01-26 12:08:38 +05:30
|
|
|
expect(page).to have_content '20 tags'
|
2021-04-17 20:07:23 +05:30
|
|
|
first_tag = first('[data-testid="name"]')
|
|
|
|
expect(first_tag).to have_content '1'
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'user removes a specific tag from container repository' do
|
2020-04-08 14:13:33 +05:30
|
|
|
service = double('service')
|
|
|
|
expect(service).to receive(:execute).with(container_repository) { { status: :success } }
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(Projects::ContainerRepository::DeleteTagsService).to receive(:new).with(container_repository.project, user, tags: ['1']) { service }
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
first('[data-testid="additional-actions"]').click
|
2020-07-28 23:09:34 +05:30
|
|
|
first('[data-testid="single-delete-button"]').click
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(find('.modal .modal-title')).to have_content _('Remove tag')
|
2023-06-20 00:43:36 +05:30
|
|
|
stub_container_registry_tags(repository: %r{my/image}, tags: ('1'..'19').to_a, with_manifest: true)
|
2020-04-08 14:13:33 +05:30
|
|
|
find('.modal .modal-footer .btn-danger').click
|
2023-06-20 00:43:36 +05:30
|
|
|
|
|
|
|
expect(page).to have_content '19 tags'
|
|
|
|
expect(page).not_to have_content '20 tags'
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
it('pagination navigate to the second page') do
|
2021-02-22 17:27:13 +05:30
|
|
|
visit_next_page
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(page).to have_content '20'
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
describe 'with a tag missing digest' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(repository: %r{my/image}, tags: %w[latest stable])
|
|
|
|
stub_next_container_registry_tags_call(:digest, nil)
|
|
|
|
visit_container_registry_details 'my/image'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the tags list correctly' do
|
|
|
|
expect(page).to have_content('latest')
|
|
|
|
expect(page).to have_content('stable')
|
2022-07-23 23:45:48 +05:30
|
|
|
expect(page).to have_content('Digest: Not applicable.')
|
2021-02-22 17:27:13 +05:30
|
|
|
end
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
[ContainerRegistry::Path::InvalidRegistryPathError, Faraday::Error].each do |error_class|
|
|
|
|
context "when there is a #{error_class}" do
|
|
|
|
before do
|
|
|
|
expect(::ContainerRegistry::Client).to receive(:registry_info).and_raise(error_class, nil, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'handling feature network errors with the container registry'
|
|
|
|
end
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe 'image repo details when image has no name' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(tags: %w[latest], with_manifest: true)
|
|
|
|
project.container_repositories << nameless_container_repository
|
|
|
|
visit_container_registry
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders correctly' do
|
|
|
|
find('a[data-testid="details-link"]').click
|
|
|
|
|
|
|
|
expect(page).to have_content 'latest'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
context 'when there are more than 10 images' do
|
|
|
|
before do
|
|
|
|
project.container_repositories << container_repository
|
2021-02-22 17:27:13 +05:30
|
|
|
create_list(:container_repository, 12, project: project)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
visit_container_registry
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'shows pagination' do
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(page).to have_css '.gl-keyset-pagination'
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'pagination goes to second page' do
|
2021-02-22 17:27:13 +05:30
|
|
|
visit_next_page
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(page).to have_content 'my/image'
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'pagination is preserved after navigating back from details' do
|
2021-02-22 17:27:13 +05:30
|
|
|
visit_next_page
|
2020-04-22 19:07:51 +05:30
|
|
|
click_link 'my/image'
|
|
|
|
breadcrumb = find '.breadcrumbs'
|
|
|
|
breadcrumb.click_link 'Container Registry'
|
|
|
|
expect(page).to have_content 'my/image'
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def visit_container_registry
|
|
|
|
visit project_container_registry_index_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def visit_container_registry_details(name)
|
|
|
|
visit_container_registry
|
2020-04-22 19:07:51 +05:30
|
|
|
click_link name
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
def visit_next_page
|
|
|
|
pagination = find '.gl-keyset-pagination'
|
|
|
|
pagination.click_button 'Next'
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|