1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe DisableExpirationPoliciesLinkedToNoContainerImages, feature_category: :container_registry do
let(:projects) { table(:projects) }
let(:container_expiration_policies) { table(:container_expiration_policies) }
let(:container_repositories) { table(:container_repositories) }
let(:namespaces) { table(:namespaces) }
let!(:namespace) { namespaces.create!(name: 'test', path: 'test') }
let!(:project) { projects.create!(id: 1, namespace_id: namespace.id, name: 'gitlab1') }
let!(:container_expiration_policy) { container_expiration_policies.create!(project_id: project.id, enabled: true) }
before do
projects.create!(id: 2, namespace_id: namespace.id, name: 'gitlab2')
container_expiration_policies.create!(project_id: 2, enabled: true)
container_repositories.create!(id: 1, project_id: 2, name: 'image2')
projects.create!(id: 3, namespace_id: namespace.id, name: 'gitlab3')
container_expiration_policies.create!(project_id: 3, enabled: false)
container_repositories.create!(id: 2, project_id: 3, name: 'image3')
end
it 'correctly disable expiration policies linked to no container images' do
expect(enabled_policies.count).to eq 2
expect(disabled_policies.count).to eq 1
expect(container_expiration_policy.enabled).to eq true
migrate!
expect(enabled_policies.count).to eq 1
expect(disabled_policies.count).to eq 2
expect(container_expiration_policy.reload.enabled).to eq false
end
def enabled_policies
container_expiration_policies.where(enabled: true)
end
def disabled_policies
container_expiration_policies.where(enabled: false)
end
end
|