diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-11 18:07:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-11 18:07:49 +0300 |
commit | 90184b64bb3412cfd291b45c8997671cdb1ca95a (patch) | |
tree | 49accc148b0fa776d8a60c9e3a9224231b7ca393 /spec/workers/container_expiration_policy_worker_spec.rb | |
parent | bac547dc784170c7d0e6a5ae14d0ff5d549c31ee (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/container_expiration_policy_worker_spec.rb')
-rw-r--r-- | spec/workers/container_expiration_policy_worker_spec.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/workers/container_expiration_policy_worker_spec.rb b/spec/workers/container_expiration_policy_worker_spec.rb new file mode 100644 index 00000000000..48ab1614633 --- /dev/null +++ b/spec/workers/container_expiration_policy_worker_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ContainerExpirationPolicyWorker do + include ExclusiveLeaseHelpers + + subject { described_class.new.perform } + + context 'With no container expiration policies' do + it 'Does not execute any policies' do + expect(ContainerExpirationPolicyService).not_to receive(:new) + + subject + end + end + + context 'With container expiration policies' do + context 'a valid policy' do + let!(:container_expiration_policy) { create(:container_expiration_policy, :runnable) } + let(:user) { container_expiration_policy.project.owner } + + it 'runs the policy' do + service = instance_double(ContainerExpirationPolicyService, execute: true) + + expect(ContainerExpirationPolicyService) + .to receive(:new).with(container_expiration_policy.project, user).and_return(service) + + subject + end + end + + context 'a disabled policy' do + let!(:container_expiration_policy) { create(:container_expiration_policy, :runnable, :disabled) } + let(:user) {container_expiration_policy.project.owner } + + it 'does not run the policy' do + expect(ContainerExpirationPolicyService) + .not_to receive(:new).with(container_expiration_policy, user) + + subject + end + end + + context 'a policy that is not due for a run' do + let!(:container_expiration_policy) { create(:container_expiration_policy) } + let(:user) {container_expiration_policy.project.owner } + + it 'does not run the policy' do + expect(ContainerExpirationPolicyService) + .not_to receive(:new).with(container_expiration_policy, user) + + subject + end + end + end +end |