debian-mirror-gitlab/spec/requests/api/container_registry_event_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2.2 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe API::ContainerRegistryEvent do
2020-04-22 19:07:51 +05:30
let(:secret_token) { 'secret_token' }
2023-02-26 17:17:37 +05:30
let(:events) { [{ action: 'push' }, { action: 'pull' }] }
2020-04-22 19:07:51 +05:30
let(:registry_headers) { { 'Content-Type' => ::API::ContainerRegistryEvent::DOCKER_DISTRIBUTION_EVENTS_V1_JSON } }
describe 'POST /container_registry_event/events' do
before do
allow(Gitlab.config.registry).to receive(:notification_secret) { secret_token }
end
2022-07-16 23:28:13 +05:30
subject(:post_events) do
2020-04-22 19:07:51 +05:30
post api('/container_registry_event/events'),
params: { events: events }.to_json,
headers: registry_headers.merge('Authorization' => secret_token)
end
it 'returns 200 status and events are passed to event handler' do
2023-02-26 17:17:37 +05:30
allow_next_instance_of(::ContainerRegistry::Event) do |event|
if event.supported?
expect(event).to receive(:handle!).once
expect(event).to receive(:track!).once
end
end
2020-04-22 19:07:51 +05:30
2022-07-16 23:28:13 +05:30
post_events
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:ok)
end
it 'returns 401 error status when token is invalid' do
post api('/container_registry_event/events'),
params: { events: events }.to_json,
headers: registry_headers.merge('Authorization' => 'invalid_token')
expect(response).to have_gitlab_http_status(:unauthorized)
end
2022-07-16 23:28:13 +05:30
context 'when the event should update project statistics' do
let_it_be(:project) { create(:project) }
let(:events) do
[
{
action: 'push',
target: {
tag: 'latest',
repository: project.full_path
}
},
{
action: 'delete',
target: {
tag: 'latest',
repository: project.full_path
}
}
]
end
it 'enqueues a project statistics update twice' do
expect(ProjectCacheWorker)
.to receive(:perform_async)
.with(project.id, [], [:container_registry_size])
.twice.and_call_original
expect { post_events }.to change { ProjectCacheWorker.jobs.size }.from(0).to(1)
end
end
2020-04-22 19:07:51 +05:30
end
end