Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSteve Abrams <sabrams@gitlab.com>2019-06-19 01:08:30 +0300
committerMayra Cabrera <mcabrera@gitlab.com>2019-06-19 01:08:30 +0300
commit34a283f90a56914306f77384e7b54c2dbd2e467a (patch)
tree022132b6fa8aa927f0e5ac5cc3b1292ec4efe3f9 /spec
parent6fa900547dbd30b0db0070f87dbeb4b05d485b9b (diff)
Add 2nd response for container api bulk delete
The bulk delete api endpoint for container registries can only be called once per hour. If a user calls the endpoint more than once per hour, they will now receive a 400 error with a descriptive message.
Diffstat (limited to 'spec')
-rw-r--r--spec/requests/api/container_registry_spec.rb21
-rw-r--r--spec/workers/cleanup_container_repository_worker_spec.rb8
2 files changed, 21 insertions, 8 deletions
diff --git a/spec/requests/api/container_registry_spec.rb b/spec/requests/api/container_registry_spec.rb
index 4ad15ed6bea..b64f3ea1081 100644
--- a/spec/requests/api/container_registry_spec.rb
+++ b/spec/requests/api/container_registry_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe API::ContainerRegistry do
+ include ExclusiveLeaseHelpers
+
set(:project) { create(:project, :private) }
set(:maintainer) { create(:user) }
set(:developer) { create(:user) }
@@ -155,7 +157,10 @@ describe API::ContainerRegistry do
older_than: '1 day' }
end
+ let(:lease_key) { "container_repository:cleanup_tags:#{root_repository.id}" }
+
it 'schedules cleanup of tags repository' do
+ stub_exclusive_lease(lease_key, timeout: 1.hour)
expect(CleanupContainerRepositoryWorker).to receive(:perform_async)
.with(maintainer.id, root_repository.id, worker_params)
@@ -163,6 +168,22 @@ describe API::ContainerRegistry do
expect(response).to have_gitlab_http_status(:accepted)
end
+
+ context 'called multiple times in one hour' do
+ it 'returns 400 with an error message' do
+ stub_exclusive_lease_taken(lease_key, timeout: 1.hour)
+ subject
+
+ expect(response).to have_gitlab_http_status(400)
+ expect(response.body).to include('This request has already been made.')
+ end
+
+ it 'executes service only for the first time' do
+ expect(CleanupContainerRepositoryWorker).to receive(:perform_async).once
+
+ 2.times { subject }
+ end
+ end
end
end
end
diff --git a/spec/workers/cleanup_container_repository_worker_spec.rb b/spec/workers/cleanup_container_repository_worker_spec.rb
index 5bee7294010..9be8f882785 100644
--- a/spec/workers/cleanup_container_repository_worker_spec.rb
+++ b/spec/workers/cleanup_container_repository_worker_spec.rb
@@ -35,13 +35,5 @@ describe CleanupContainerRepositoryWorker, :clean_gitlab_redis_shared_state do
subject.perform(user.id, -1, params)
end.not_to raise_error
end
-
- context 'when executed twice in short period' do
- it 'executes service only for the first time' do
- expect(service).to receive(:execute).once
-
- 2.times { subject.perform(user.id, repository.id, params) }
- end
- end
end
end