diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/models/container_registry/event_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/models/container_registry/event_spec.rb')
-rw-r--r-- | spec/models/container_registry/event_spec.rb | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/spec/models/container_registry/event_spec.rb b/spec/models/container_registry/event_spec.rb index 21a3ab5363a..6b544c95cc8 100644 --- a/spec/models/container_registry/event_spec.rb +++ b/spec/models/container_registry/event_spec.rb @@ -26,11 +26,65 @@ RSpec.describe ContainerRegistry::Event do end describe '#handle!' do - let(:raw_event) { { 'action' => 'push', 'target' => { 'mediaType' => ContainerRegistry::Client::DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE } } } + let(:action) { 'push' } + let(:repository) { project.full_path } + let(:target) do + { + 'mediaType' => ContainerRegistry::Client::DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE, + 'tag' => 'latest', + 'repository' => repository + } + end + + let(:raw_event) { { 'action' => action, 'target' => target } } + + subject(:handle!) { described_class.new(raw_event).handle! } + + it 'enqueues a project statistics update' do + expect(ProjectCacheWorker).to receive(:perform_async).with(project.id, [], [:container_registry_size]) + + handle! + end - subject { described_class.new(raw_event).handle! } + shared_examples 'event without project statistics update' do + it 'does not queue a project statistics update' do + expect(ProjectCacheWorker).not_to receive(:perform_async) - it { is_expected.to eq nil } + handle! + end + end + + context 'with :container_registry_project_statistics feature flag disabled' do + before do + stub_feature_flags(container_registry_project_statistics: false) + end + + it_behaves_like 'event without project statistics update' + end + + context 'with no target tag' do + let(:target) { super().without('tag') } + + it_behaves_like 'event without project statistics update' + end + + context 'with an unsupported action' do + let(:action) { 'pull' } + + it_behaves_like 'event without project statistics update' + end + + context 'with an invalid project repository path' do + let(:repository) { 'does/not/exist' } + + it_behaves_like 'event without project statistics update' + end + + context 'with no project repository path' do + let(:repository) { nil } + + it_behaves_like 'event without project statistics update' + end end describe '#track!' do |