diff options
Diffstat (limited to 'spec/services/projects/container_repository')
3 files changed, 84 insertions, 75 deletions
diff --git a/spec/services/projects/container_repository/cleanup_tags_service_spec.rb b/spec/services/projects/container_repository/cleanup_tags_service_spec.rb index 86c0ba4222c..79904e2bf72 100644 --- a/spec/services/projects/container_repository/cleanup_tags_service_spec.rb +++ b/spec/services/projects/container_repository/cleanup_tags_service_spec.rb @@ -34,8 +34,6 @@ RSpec.describe Projects::ContainerRepository::CleanupTagsService, :clean_gitlab_ stub_digest_config('sha256:configB', 5.days.ago) stub_digest_config('sha256:configC', 1.month.ago) stub_digest_config('sha256:configD', nil) - - stub_feature_flags(container_registry_expiration_policies_throttling: false) end describe '#execute' do @@ -334,24 +332,17 @@ RSpec.describe Projects::ContainerRepository::CleanupTagsService, :clean_gitlab_ end end - where(:feature_flag_enabled, :max_list_size, :delete_tags_service_status, :expected_status, :expected_truncated) do - false | 10 | :success | :success | false - false | 10 | :error | :error | false - false | 3 | :success | :success | false - false | 3 | :error | :error | false - false | 0 | :success | :success | false - false | 0 | :error | :error | false - true | 10 | :success | :success | false - true | 10 | :error | :error | false - true | 3 | :success | :error | true - true | 3 | :error | :error | true - true | 0 | :success | :success | false - true | 0 | :error | :error | false + where(:max_list_size, :delete_tags_service_status, :expected_status, :expected_truncated) do + 10 | :success | :success | false + 10 | :error | :error | false + 3 | :success | :error | true + 3 | :error | :error | true + 0 | :success | :success | false + 0 | :error | :error | false end with_them do before do - stub_feature_flags(container_registry_expiration_policies_throttling: feature_flag_enabled) stub_application_setting(container_registry_cleanup_tags_service_max_list_size: max_list_size) allow_next_instance_of(Projects::ContainerRepository::DeleteTagsService) do |service| expect(service).to receive(:execute).and_return(status: delete_tags_service_status) @@ -429,10 +420,10 @@ RSpec.describe Projects::ContainerRepository::CleanupTagsService, :clean_gitlab_ end # We will ping the container registry for all tags *except* for C because it's cached - expect(ContainerRegistry::Blob).to receive(:new).with(repository, "digest" => "sha256:configA").and_call_original - expect(ContainerRegistry::Blob).to receive(:new).with(repository, "digest" => "sha256:configB").twice.and_call_original - expect(ContainerRegistry::Blob).not_to receive(:new).with(repository, "digest" => "sha256:configC") - expect(ContainerRegistry::Blob).to receive(:new).with(repository, "digest" => "sha256:configD").and_call_original + expect(ContainerRegistry::Blob).to receive(:new).with(repository, { "digest" => "sha256:configA" }).and_call_original + expect(ContainerRegistry::Blob).to receive(:new).with(repository, { "digest" => "sha256:configB" }).twice.and_call_original + expect(ContainerRegistry::Blob).not_to receive(:new).with(repository, { "digest" => "sha256:configC" }) + expect(ContainerRegistry::Blob).to receive(:new).with(repository, { "digest" => "sha256:configD" }).and_call_original expect(subject).to include(cached_tags_count: 1) end diff --git a/spec/services/projects/container_repository/delete_tags_service_spec.rb b/spec/services/projects/container_repository/delete_tags_service_spec.rb index 246ca301cfa..9e6849aa514 100644 --- a/spec/services/projects/container_repository/delete_tags_service_spec.rb +++ b/spec/services/projects/container_repository/delete_tags_service_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' RSpec.describe Projects::ContainerRepository::DeleteTagsService do + using RSpec::Parameterized::TableSyntax include_context 'container repository delete tags service shared context' let(:service) { described_class.new(project, user, params) } @@ -17,11 +18,13 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do shared_examples 'logging a success response' do it 'logs an info message' do expect(service).to receive(:log_info).with( - service_class: 'Projects::ContainerRepository::DeleteTagsService', - message: 'deleted tags', - container_repository_id: repository.id, - project_id: repository.project_id, - deleted_tags_count: tags.size + { + service_class: 'Projects::ContainerRepository::DeleteTagsService', + message: 'deleted tags', + container_repository_id: repository.id, + project_id: repository.project_id, + deleted_tags_count: tags.size + } ) subject @@ -131,10 +134,6 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do subject { service.execute(repository) } - before do - stub_feature_flags(container_registry_expiration_policies_throttling: false) - end - context 'without permissions' do it { is_expected.to include(status: :error) } end @@ -157,11 +156,39 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do end context 'when the repository is importing' do - before do - repository.update_columns(migration_state: 'importing', migration_import_started_at: Time.zone.now) + where(:migration_state, :called_by_policy, :error_expected) do + 'default' | false | false + 'default' | true | false + 'pre_importing' | false | false + 'pre_importing' | true | true + 'pre_import_done' | false | false + 'pre_import_done' | true | true + 'importing' | false | true + 'importing' | true | true + 'import_done' | false | false + 'import_done' | true | false + 'import_aborted' | false | false + 'import_aborted' | true | false + 'import_skipped' | false | false + 'import_skipped' | true | false end - it { is_expected.to include(status: :error, message: 'repository importing') } + with_them do + let(:params) { { tags: tags, container_expiration_policy: called_by_policy ? true : nil } } + + before do + repository.update_columns(migration_state: migration_state, migration_import_started_at: Time.zone.now, migration_pre_import_started_at: Time.zone.now, migration_pre_import_done_at: Time.zone.now) + end + + it 'returns an error response if expected' do + if error_expected + expect(subject).to include(status: :error, message: 'repository importing') + else + expect(service).to receive(:delete_tags).and_return(status: :success) + expect(subject).not_to include(status: :error) + end + end + end end end diff --git a/spec/services/projects/container_repository/gitlab/delete_tags_service_spec.rb b/spec/services/projects/container_repository/gitlab/delete_tags_service_spec.rb index 74f782538c5..8d8907119f0 100644 --- a/spec/services/projects/container_repository/gitlab/delete_tags_service_spec.rb +++ b/spec/services/projects/container_repository/gitlab/delete_tags_service_spec.rb @@ -12,10 +12,6 @@ RSpec.describe Projects::ContainerRepository::Gitlab::DeleteTagsService do subject { service.execute } - before do - stub_feature_flags(container_registry_expiration_policies_throttling: false) - end - RSpec.shared_examples 'deleting tags' do it 'deletes the tags by name' do stub_delete_reference_requests(tags) @@ -26,6 +22,8 @@ RSpec.describe Projects::ContainerRepository::Gitlab::DeleteTagsService do end context 'with tags to delete' do + let(:timeout) { 10 } + it_behaves_like 'deleting tags' it 'succeeds when tag delete returns 404' do @@ -50,59 +48,52 @@ RSpec.describe Projects::ContainerRepository::Gitlab::DeleteTagsService do end end - context 'with throttling enabled' do - let(:timeout) { 10 } - - before do - stub_feature_flags(container_registry_expiration_policies_throttling: true) - stub_application_setting(container_registry_delete_tags_service_timeout: timeout) - end - - it_behaves_like 'deleting tags' + before do + stub_application_setting(container_registry_delete_tags_service_timeout: timeout) + end - context 'with timeout' do - context 'set to a valid value' do - before do - allow(Time.zone).to receive(:now).and_return(10, 15, 25) # third call to Time.zone.now will be triggering the timeout - stub_delete_reference_requests('A' => 200) - end + context 'with timeout' do + context 'set to a valid value' do + before do + allow(Time.zone).to receive(:now).and_return(10, 15, 25) # third call to Time.zone.now will be triggering the timeout + stub_delete_reference_requests('A' => 200) + end - it { is_expected.to eq(status: :error, message: 'error while deleting tags', deleted: ['A'], exception_class_name: Projects::ContainerRepository::Gitlab::DeleteTagsService::TimeoutError.name) } + it { is_expected.to eq(status: :error, message: 'error while deleting tags', deleted: ['A'], exception_class_name: Projects::ContainerRepository::Gitlab::DeleteTagsService::TimeoutError.name) } - it 'tracks the exception' do - expect(::Gitlab::ErrorTracking) - .to receive(:track_exception).with(::Projects::ContainerRepository::Gitlab::DeleteTagsService::TimeoutError, tags_count: tags.size, container_repository_id: repository.id) + it 'tracks the exception' do + expect(::Gitlab::ErrorTracking) + .to receive(:track_exception).with(::Projects::ContainerRepository::Gitlab::DeleteTagsService::TimeoutError, tags_count: tags.size, container_repository_id: repository.id) - subject - end + subject end + end - context 'set to 0' do - let(:timeout) { 0 } + context 'set to 0' do + let(:timeout) { 0 } - it_behaves_like 'deleting tags' - end + it_behaves_like 'deleting tags' + end - context 'set to nil' do - let(:timeout) { nil } + context 'set to nil' do + let(:timeout) { nil } - it_behaves_like 'deleting tags' - end + it_behaves_like 'deleting tags' end + end - context 'with a network error' do - before do - expect(service).to receive(:delete_tags).and_raise(::Faraday::TimeoutError) - end + context 'with a network error' do + before do + expect(service).to receive(:delete_tags).and_raise(::Faraday::TimeoutError) + end - it { is_expected.to eq(status: :error, message: 'error while deleting tags', deleted: [], exception_class_name: ::Faraday::TimeoutError.name) } + it { is_expected.to eq(status: :error, message: 'error while deleting tags', deleted: [], exception_class_name: ::Faraday::TimeoutError.name) } - it 'tracks the exception' do - expect(::Gitlab::ErrorTracking) - .to receive(:track_exception).with(::Faraday::TimeoutError, tags_count: tags.size, container_repository_id: repository.id) + it 'tracks the exception' do + expect(::Gitlab::ErrorTracking) + .to receive(:track_exception).with(::Faraday::TimeoutError, tags_count: tags.size, container_repository_id: repository.id) - subject - end + subject end end end |