debian-mirror-gitlab/spec/controllers/groups/registry/repositories_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

176 lines
4.9 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Groups::Registry::RepositoriesController do
2019-12-21 20:55:43 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:guest) { create(:user) }
let_it_be(:group, reload: true) { create(:group) }
2021-04-29 21:17:54 +05:30
2020-05-24 23:13:21 +05:30
let(:additional_parameters) { {} }
2019-12-21 20:55:43 +05:30
2020-04-22 19:07:51 +05:30
subject do
2020-05-24 23:13:21 +05:30
get :index, params: additional_parameters.merge({
2020-04-22 19:07:51 +05:30
group_id: group,
format: format
2020-05-24 23:13:21 +05:30
})
2020-04-22 19:07:51 +05:30
end
2019-12-21 20:55:43 +05:30
before do
stub_container_registry_config(enabled: true)
2020-06-23 00:09:42 +05:30
stub_container_registry_tags(repository: :any, tags: [])
2021-11-18 22:05:49 +05:30
stub_container_registry_info
2019-12-21 20:55:43 +05:30
group.add_owner(user)
group.add_guest(guest)
sign_in(user)
end
2020-03-13 15:44:24 +05:30
shared_examples 'renders a list of repositories' do
2020-04-22 19:07:51 +05:30
let_it_be(:repo) { create_project_with_repo(test_group) }
2020-03-13 15:44:24 +05:30
2020-04-22 19:07:51 +05:30
it 'returns a list of projects for json format' do
subject
2019-12-21 20:55:43 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_kind_of(Array)
expect(json_response.first).to include(
'id' => repo.id,
'name' => repo.name
)
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
it 'displays a connection error message' do
expect(::ContainerRegistry::Client).to receive(:registry_info).and_raise(error_class, nil, nil)
subject
expect(response).to have_gitlab_http_status(:ok)
end
end
end
2020-04-22 19:07:51 +05:30
end
2019-12-21 20:55:43 +05:30
2020-05-24 23:13:21 +05:30
shared_examples 'with name parameter' do
let_it_be(:project) { create(:project, group: test_group) }
let_it_be(:repo) { create(:container_repository, project: project, name: 'my_searched_image') }
let_it_be(:another_repo) { create(:container_repository, project: project, name: 'bar') }
let(:additional_parameters) { { name: 'my_searched_image' } }
it 'returns the searched repo' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.length).to eq 1
expect(json_response.first).to include(
'id' => repo.id,
'name' => repo.name
)
end
end
2020-04-22 19:07:51 +05:30
shared_examples 'renders correctly' do
context 'when user has access to registry' do
let_it_be(:test_group) { group }
2019-12-21 20:55:43 +05:30
2020-04-22 19:07:51 +05:30
context 'html format' do
let(:format) { :html }
2019-12-21 20:55:43 +05:30
2021-01-29 00:20:46 +05:30
it 'show index page', :snowplow do
2020-04-22 19:07:51 +05:30
subject
2019-12-21 20:55:43 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:ok)
2021-01-29 00:20:46 +05:30
expect_no_snowplow_event
2020-04-22 19:07:51 +05:30
end
2021-11-18 22:05:49 +05:30
[ContainerRegistry::Path::InvalidRegistryPathError, Faraday::Error].each do |error_class|
context "when there is an invalid path error #{error_class}" do
it 'displays a connection error message' do
expect(::ContainerRegistry::Client).to receive(:registry_info).and_raise(error_class, nil, nil)
subject
expect(response).to have_gitlab_http_status(:ok)
end
end
end
2019-12-21 20:55:43 +05:30
end
2020-04-22 19:07:51 +05:30
context 'json format' do
let(:format) { :json }
2021-09-04 01:27:46 +05:30
let(:namespace) { group }
let(:snowplow_gitlab_standard_context) { { user: user, namespace: group } }
2020-04-22 19:07:51 +05:30
it 'has the correct response schema' do
subject
2019-12-21 20:55:43 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to match_response_schema('registry/repositories')
expect(response).to include_pagination_headers
end
2019-12-21 20:55:43 +05:30
2020-04-22 19:07:51 +05:30
it_behaves_like 'renders a list of repositories'
2020-05-24 23:13:21 +05:30
it_behaves_like 'with name parameter'
2021-01-03 14:25:43 +05:30
it_behaves_like 'a package tracking event', described_class.name, 'list_repositories'
2020-04-22 19:07:51 +05:30
context 'with project in subgroup' do
let_it_be(:test_group) { create(:group, parent: group ) }
it_behaves_like 'renders a list of repositories'
2020-05-24 23:13:21 +05:30
it_behaves_like 'with name parameter'
2020-04-22 19:07:51 +05:30
context 'with project in subgroup and group' do
let_it_be(:repo_in_test_group) { create_project_with_repo(test_group) }
let_it_be(:repo_in_group) { create_project_with_repo(group) }
it 'returns all the projects' do
subject
expect(json_response).to be_kind_of(Array)
expect(json_response.length).to eq 2
end
2020-05-24 23:13:21 +05:30
it_behaves_like 'with name parameter'
2020-04-22 19:07:51 +05:30
end
end
2019-12-21 20:55:43 +05:30
end
end
2020-04-22 19:07:51 +05:30
context 'user does not have access to container registry' do
2019-12-21 20:55:43 +05:30
before do
sign_out(user)
sign_in(guest)
end
2020-04-22 19:07:51 +05:30
context 'json format' do
let(:format) { :json }
2020-03-13 15:44:24 +05:30
2020-04-22 19:07:51 +05:30
it_behaves_like 'returning response status', :not_found
2020-03-13 15:44:24 +05:30
end
2020-04-22 19:07:51 +05:30
context 'html format' do
let(:format) { :html }
2020-03-13 15:44:24 +05:30
2020-04-22 19:07:51 +05:30
it_behaves_like 'returning response status', :not_found
2020-03-13 15:44:24 +05:30
end
end
end
context 'GET #index' do
2020-04-22 19:07:51 +05:30
it_behaves_like 'renders correctly'
2020-03-13 15:44:24 +05:30
end
context 'GET #show' do
2020-04-22 19:07:51 +05:30
it_behaves_like 'renders correctly'
end
def create_project_with_repo(group)
project = create(:project, group: test_group)
create(:container_repository, project: project)
2019-12-21 20:55:43 +05:30
end
end