diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-24 15:06:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-24 15:06:49 +0300 |
commit | af5193aa3cc159fd7d08be988bd00f1921077117 (patch) | |
tree | 664d9936ab99208c49b8721877be87b7e420d5bd /spec/requests/projects/gcp/artifact_registry/docker_images_controller_spec.rb | |
parent | 4dcdd5bebb55bd5522ec180070d4d265e00943b5 (diff) |
Diffstat (limited to 'spec/requests/projects/gcp/artifact_registry/docker_images_controller_spec.rb')
-rw-r--r-- | spec/requests/projects/gcp/artifact_registry/docker_images_controller_spec.rb | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/spec/requests/projects/gcp/artifact_registry/docker_images_controller_spec.rb b/spec/requests/projects/gcp/artifact_registry/docker_images_controller_spec.rb deleted file mode 100644 index f1c87243516..00000000000 --- a/spec/requests/projects/gcp/artifact_registry/docker_images_controller_spec.rb +++ /dev/null @@ -1,137 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Projects::Gcp::ArtifactRegistry::DockerImagesController, feature_category: :container_registry do - let_it_be(:project) { create(:project, :private) } - - let(:user) { project.owner } - let(:gcp_project_id) { 'gcp_project_id' } - let(:gcp_location) { 'gcp_location' } - let(:gcp_ar_repository) { 'gcp_ar_repository' } - let(:gcp_wlif_url) { 'gcp_wlif_url' } - - describe '#index' do - let(:service_response) { ServiceResponse.success(payload: dummy_client_payload) } - let(:service_double) do - instance_double('GoogleCloudPlatform::ArtifactRegistry::ListDockerImagesService') - end - - subject(:get_index_page) do - get( - project_gcp_artifact_registry_docker_images_path( - project, - gcp_project_id: gcp_project_id, - gcp_location: gcp_location, - gcp_ar_repository: gcp_ar_repository, - gcp_wlif_url: gcp_wlif_url - ) - ) - end - - before do - allow_next_instance_of(GoogleCloudPlatform::ArtifactRegistry::ListDockerImagesService) do |service| - allow(service).to receive(:execute).and_return(service_response) - end - end - - shared_examples 'returning the error message' do |message| - it 'displays an error message' do - sign_in(user) - - get_index_page - - expect(response).to have_gitlab_http_status(:success) - expect(response.body).to include(message) - end - end - - context 'when on saas', :saas do - it 'returns the images' do - sign_in(user) - - get_index_page - - expect(response).to have_gitlab_http_status(:success) - expect(response.body).to include('image@sha256:6a') - expect(response.body).to include('tag1') - expect(response.body).to include('tag2') - expect(response.body).to include('Prev') - expect(response.body).to include('Next') - expect(response.body).to include('https://location.pkg.dev/project/repo/image@sha256:6a') - end - - context 'when the service returns an error response' do - let(:service_response) { ServiceResponse.error(message: 'boom') } - - it_behaves_like 'returning the error message', 'boom' - end - - %i[gcp_project_id gcp_location gcp_ar_repository gcp_wlif_url].each do |field| - context "when a gcp parameter #{field} is missing" do - let(field) { nil } - - it 'redirects to setup page' do - sign_in(user) - - get_index_page - - expect(response).to redirect_to new_project_gcp_artifact_registry_setup_path(project) - end - end - end - - context 'with the feature flag disabled' do - before do - stub_feature_flags(gcp_technical_demo: false) - end - - it_behaves_like 'returning the error message', 'Feature flag disabled' - end - - context 'with non private project' do - before do - allow_next_found_instance_of(Project) do |project| - allow(project).to receive(:private?).and_return(false) - end - end - - it_behaves_like 'returning the error message', 'Can only run on private projects' - end - - context 'with unauthorized user' do - let_it_be(:user) { create(:user) } - - it 'returns success' do - sign_in(user) - - get_index_page - - expect(response).to have_gitlab_http_status(:not_found) - end - end - end - - context 'when not on saas' do - it_behaves_like 'returning the error message', "Can't run here" - end - - def dummy_client_payload - { - images: [ - { - built_at: '2023-11-30T23:23:11.980068941Z', - media_type: 'application/vnd.docker.distribution.manifest.v2+json', - name: 'projects/project/locations/location/repositories/repo/dockerImages/image@sha256:6a', - size_bytes: 2827903, - tags: %w[tag1 tag2], - updated_at: '2023-12-07T11:48:50.840751Z', - uploaded_at: '2023-12-07T11:48:47.598511Z', - uri: 'location.pkg.dev/project/repo/image@sha256:6a' - } - ], - next_page_token: 'next_page_token' - } - end - end -end |