2020-01-16 12:08:32 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration policy', :js do
|
2020-01-16 12:08:32 +00:00
|
|
|
let(:user) { create(:user) }
|
2020-01-24 15:09:00 +00:00
|
|
|
let(:project) { create(:project, namespace: user.namespace, container_registry_enabled: container_registry_enabled) }
|
|
|
|
let(:container_registry_enabled) { true }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
stub_container_registry_config(enabled: true)
|
2020-02-21 06:08:58 +00:00
|
|
|
stub_feature_flags(new_variables_ui: false)
|
2020-01-24 15:09:00 +00:00
|
|
|
end
|
2020-01-16 12:08:32 +00:00
|
|
|
|
|
|
|
context 'as owner' do
|
|
|
|
before do
|
|
|
|
visit project_settings_ci_cd_path(project)
|
|
|
|
end
|
|
|
|
|
2020-01-24 15:09:00 +00:00
|
|
|
it 'shows available section' do
|
2020-01-16 12:08:32 +00:00
|
|
|
settings_block = find('#js-registry-policies')
|
|
|
|
expect(settings_block).to have_text 'Container Registry tag expiration policy'
|
|
|
|
end
|
|
|
|
|
2020-01-24 15:09:00 +00:00
|
|
|
it 'saves expiration policy submit the form' do
|
2020-01-16 12:08:32 +00:00
|
|
|
within '#js-registry-policies' do
|
|
|
|
within '.card-body' do
|
2020-02-03 09:08:42 +00:00
|
|
|
select('7 days until tags are automatically removed', from: 'Expiration interval:')
|
|
|
|
select('Every day', from: 'Expiration schedule:')
|
|
|
|
select('50 tags per image name', from: 'Number of tags to retain:')
|
2020-06-11 12:08:54 +00:00
|
|
|
fill_in('Tags with names matching this regex pattern will expire:', with: '.*-production')
|
2020-01-16 12:08:32 +00:00
|
|
|
end
|
|
|
|
submit_button = find('.card-footer .btn.btn-success')
|
|
|
|
expect(submit_button).not_to be_disabled
|
|
|
|
submit_button.click
|
|
|
|
end
|
2020-01-21 18:07:31 +00:00
|
|
|
toast = find('.gl-toast')
|
|
|
|
expect(toast).to have_content('Expiration policy successfully saved.')
|
2020-01-16 12:08:32 +00:00
|
|
|
end
|
2020-06-11 12:08:54 +00:00
|
|
|
|
|
|
|
it 'does not save expiration policy submit form with invalid regex' do
|
|
|
|
within '#js-registry-policies' do
|
|
|
|
within '.card-body' do
|
|
|
|
fill_in('Tags with names matching this regex pattern will expire:', with: '*-production')
|
|
|
|
end
|
|
|
|
submit_button = find('.card-footer .btn.btn-success')
|
|
|
|
expect(submit_button).not_to be_disabled
|
|
|
|
submit_button.click
|
|
|
|
end
|
|
|
|
toast = find('.gl-toast')
|
|
|
|
expect(toast).to have_content('Something went wrong while updating the expiration policy.')
|
|
|
|
end
|
2020-01-16 12:08:32 +00:00
|
|
|
end
|
2020-01-24 15:09:00 +00:00
|
|
|
|
|
|
|
context 'when registry is disabled' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(enabled: false)
|
|
|
|
visit project_settings_ci_cd_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not exists' do
|
|
|
|
expect(page).not_to have_selector('#js-registry-policies')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when container registry is disabled on project' do
|
|
|
|
let(:container_registry_enabled) { false }
|
|
|
|
|
|
|
|
before do
|
|
|
|
visit project_settings_ci_cd_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not exists' do
|
|
|
|
expect(page).not_to have_selector('#js-registry-policies')
|
|
|
|
end
|
|
|
|
end
|
2020-01-16 12:08:32 +00:00
|
|
|
end
|