diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-30 09:07:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-30 09:07:58 +0000 |
commit | 45b4df3e57c949c88107840c44ccbfaf2eabdf26 (patch) | |
tree | f73c1533a75b03d2ceb1361644e0d8ab97568a8f /spec/models | |
parent | 7421e6f9f2b5889b05738af7eba568af6ae3fcbc (diff) | |
download | gitlab-ce-45b4df3e57c949c88107840c44ccbfaf2eabdf26.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/container_registry/event_spec.rb | 92 | ||||
-rw-r--r-- | spec/models/container_repository_spec.rb | 12 |
2 files changed, 104 insertions, 0 deletions
diff --git a/spec/models/container_registry/event_spec.rb b/spec/models/container_registry/event_spec.rb new file mode 100644 index 00000000000..54ff218f2a8 --- /dev/null +++ b/spec/models/container_registry/event_spec.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ContainerRegistry::Event do + using RSpec::Parameterized::TableSyntax + + let_it_be(:group) { create(:group, name: 'group') } + let_it_be(:project) { create(:project, name: 'test', namespace: group) } + + describe '#supported?' do + let(:raw_event) { { 'action' => action } } + + subject { described_class.new(raw_event).supported? } + + where(:action, :supported) do + 'delete' | true + 'push' | true + 'mount' | false + 'pull' | false + end + + with_them do + it { is_expected.to eq supported } + end + end + + describe '#handle!' do + let(:raw_event) { { 'action' => 'push', 'target' => { 'mediaType' => ContainerRegistry::Client::DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE } } } + + subject { described_class.new(raw_event).handle! } + + it { is_expected.to eq nil } + end + + describe '#track!' do + let_it_be(:container_repository) { create(:container_repository, name: 'container', project: project) } + + let(:raw_event) { { 'action' => action, 'target' => target } } + + subject { described_class.new(raw_event).track! } + + context 'with a respository target' do + let(:target) do + { + 'mediaType' => ContainerRegistry::Client::DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE, + 'repository' => repository_path + } + end + + where(:repository_path, :action, :tracking_action) do + 'group/test/container' | 'push' | 'push_repository' + 'group/test/container' | 'delete' | 'delete_repository' + 'foo/bar' | 'push' | 'create_repository' + 'foo/bar' | 'delete' | 'delete_repository' + end + + with_them do + it 'creates a tracking event' do + expect(::Gitlab::Tracking).to receive(:event).with('container_registry:notification', tracking_action) + + subject + end + end + end + + context 'with a tag target' do + let(:target) do + { + 'mediaType' => ContainerRegistry::Client::DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE, + 'repository' => repository_path, + 'tag' => 'latest' + } + end + + where(:repository_path, :action, :tracking_action) do + 'group/test/container' | 'push' | 'push_tag' + 'group/test/container' | 'delete' | 'delete_tag' + 'foo/bar' | 'push' | 'push_tag' + 'foo/bar' | 'delete' | 'delete_tag' + end + + with_them do + it 'creates a tracking event' do + expect(::Gitlab::Tracking).to receive(:event).with('container_registry:notification', tracking_action) + + subject + end + end + end + end +end diff --git a/spec/models/container_repository_spec.rb b/spec/models/container_repository_spec.rb index 5ed812652c5..5bcd9dfd396 100644 --- a/spec/models/container_repository_spec.rb +++ b/spec/models/container_repository_spec.rb @@ -29,6 +29,18 @@ describe ContainerRepository do end end + describe '.exists_by_path?' do + it 'returns true for known container repository paths' do + path = ContainerRegistry::Path.new("#{project.full_path}/#{repository.name}") + expect(described_class.exists_by_path?(path)).to be_truthy + end + + it 'returns false for unknown container repository paths' do + path = ContainerRegistry::Path.new('you/dont/know/me') + expect(described_class.exists_by_path?(path)).to be_falsey + end + end + describe '#tag' do it 'has a test tag' do expect(repository.tag('test')).not_to be_nil |