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

148 lines
3.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) }
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: [])
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
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
2019-12-21 20:55:43 +05:30
end
2020-04-22 19:07:51 +05:30
context 'json format' do
let(:format) { :json }
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