2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration policy', :js do
|
2021-01-03 14:25:43 +05:30
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project, reload: true) { create(:project, namespace: user.namespace) }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:container_registry_enabled) { true }
|
2021-01-03 14:25:43 +05:30
|
|
|
let(:container_registry_enabled_on_project) { true }
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
shared_examples 'an expiration policy form' do
|
|
|
|
before do
|
|
|
|
project.update!(container_registry_enabled: container_registry_enabled_on_project)
|
|
|
|
project.container_expiration_policy.update!(enabled: true)
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
sign_in(user)
|
|
|
|
stub_container_registry_config(enabled: container_registry_enabled)
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'as owner' do
|
|
|
|
it 'shows available section' do
|
|
|
|
subject
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
settings_block = find('[data-testid="registry-settings-app"]')
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(settings_block).to have_text 'Clean up image tags'
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'saves cleanup policy submit the form' do
|
|
|
|
subject
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
within '[data-testid="registry-settings-app"]' do
|
2021-06-08 01:23:25 +05:30
|
|
|
select('Every day', from: 'Run cleanup')
|
|
|
|
select('50 tags per image name', from: 'Keep the most recent:')
|
|
|
|
fill_in('Keep tags matching:', with: 'stable')
|
|
|
|
select('7 days', from: 'Remove tags older than:')
|
|
|
|
fill_in('Remove tags matching:', with: '.*-production')
|
|
|
|
|
|
|
|
submit_button = find('[data-testid="save-button"')
|
|
|
|
expect(submit_button).not_to be_disabled
|
|
|
|
submit_button.click
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(find('.gl-toast')).to have_content('Cleanup policy successfully saved.')
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'does not save cleanup policy submit form with invalid regex' do
|
|
|
|
subject
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
within '[data-testid="registry-settings-app"]' do
|
2021-06-08 01:23:25 +05:30
|
|
|
fill_in('Remove tags matching:', with: '*-production')
|
|
|
|
|
|
|
|
submit_button = find('[data-testid="save-button"')
|
|
|
|
expect(submit_button).not_to be_disabled
|
|
|
|
submit_button.click
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(find('.gl-toast')).to have_content('Something went wrong while updating the cleanup policy.')
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'with a project without expiration policy' do
|
|
|
|
where(:application_setting, :feature_flag, :result) do
|
|
|
|
true | true | :available_section
|
|
|
|
true | false | :available_section
|
|
|
|
false | true | :available_section
|
|
|
|
false | false | :disabled_message
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
project.container_expiration_policy.destroy!
|
|
|
|
stub_feature_flags(container_expiration_policies_historic_entry: false)
|
|
|
|
stub_application_setting(container_expiration_policies_enable_historic_entries: application_setting)
|
|
|
|
stub_feature_flags(container_expiration_policies_historic_entry: project) if feature_flag
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'displays the expected result' do
|
|
|
|
subject
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
within '[data-testid="registry-settings-app"]' do
|
2021-06-08 01:23:25 +05:30
|
|
|
case result
|
|
|
|
when :available_section
|
|
|
|
expect(find('[data-testid="enable-toggle"]')).to have_content('Disabled - Tags will not be automatically deleted.')
|
|
|
|
when :disabled_message
|
|
|
|
expect(find('.gl-alert-title')).to have_content('Cleanup policy for tags is disabled')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'when registry is disabled' do
|
|
|
|
let(:container_registry_enabled) { false }
|
|
|
|
|
|
|
|
it 'does not exists' do
|
|
|
|
subject
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(page).not_to have_selector('[data-testid="registry-settings-app"]')
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'when container registry is disabled on project' do
|
|
|
|
let(:container_registry_enabled_on_project) { false }
|
|
|
|
|
|
|
|
it 'does not exists' do
|
2021-01-03 14:25:43 +05:30
|
|
|
subject
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(page).not_to have_selector('[data-testid="registry-settings-app"]')
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'with sidebar feature flag off' do
|
|
|
|
subject { visit project_settings_ci_cd_path(project) }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
before do
|
|
|
|
stub_feature_flags(sidebar_refactor: false)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it_behaves_like 'an expiration policy form'
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'with sidebar feature flag on' do
|
|
|
|
subject { visit project_settings_packages_and_registries_path(project) }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
before do
|
|
|
|
stub_feature_flags(sidebar_refactor: true)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
it_behaves_like 'an expiration policy form'
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|