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

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

96 lines
4.3 KiB
Ruby
Raw Normal View History

2021-09-04 01:27:46 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe API::ProjectDebianDistributions, feature_category: :package_registry do
2021-09-04 01:27:46 +05:30
include HttpBasicAuthHelpers
include WorkhorseHelpers
2023-03-17 16:20:25 +05:30
include_context 'Debian repository shared context', :project, false do
shared_examples 'accept GET request on private project with access to package registry for everyone' do
include_context 'Debian repository access', :private, :anonymous, :basic do
before do
container.project_feature.reload.update!(package_registry_access_level: ProjectFeature::PUBLIC)
end
it_behaves_like 'Debian distributions GET request', :success
end
end
2021-09-04 01:27:46 +05:30
describe 'POST projects/:id/debian_distributions' do
let(:method) { :post }
let(:url) { "/projects/#{container.id}/debian_distributions" }
let(:api_params) { { 'codename': 'my-codename' } }
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian distributions write endpoint', 'POST', :created, /^{.*"codename":"my-codename",.*"components":\["main"\],.*"architectures":\["all","amd64"\]/
2021-09-04 01:27:46 +05:30
context 'with invalid parameters' do
let(:api_params) { { codename: distribution.codename } }
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian distributions write endpoint', 'GET', :bad_request, /^{"message":{"codename":\["has already been taken"\]}}$/
2021-09-04 01:27:46 +05:30
end
2023-03-17 16:20:25 +05:30
context 'with access to package registry for everyone' do
include_context 'Debian repository access', :private, :anonymous, :basic do
before do
container.project_feature.reload.update!(package_registry_access_level: ProjectFeature::PUBLIC)
end
it_behaves_like 'Debian distributions POST request', :not_found
end
end
2021-09-04 01:27:46 +05:30
end
describe 'GET projects/:id/debian_distributions' do
let(:url) { "/projects/#{container.id}/debian_distributions" }
2023-03-04 22:38:38 +05:30
it_behaves_like 'Debian distributions read endpoint', 'GET', :success, /^\[{.*"codename":"existing-codename",.*"components":\["existing-component"\],.*"architectures":\["all","existing-arch"\]/
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2021-09-04 01:27:46 +05:30
end
describe 'GET projects/:id/debian_distributions/:codename' do
let(:url) { "/projects/#{container.id}/debian_distributions/#{distribution.codename}" }
2023-03-04 22:38:38 +05:30
it_behaves_like 'Debian distributions read endpoint', 'GET', :success, /^{.*"codename":"existing-codename",.*"components":\["existing-component"\],.*"architectures":\["all","existing-arch"\]/
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2021-12-11 22:18:48 +05:30
end
describe 'GET projects/:id/debian_distributions/:codename/key.asc' do
let(:url) { "/projects/#{container.id}/debian_distributions/#{distribution.codename}/key.asc" }
it_behaves_like 'Debian distributions read endpoint', 'GET', :success, /^-----BEGIN PGP PUBLIC KEY BLOCK-----/
2023-03-17 16:20:25 +05:30
it_behaves_like 'accept GET request on private project with access to package registry for everyone'
2021-09-04 01:27:46 +05:30
end
describe 'PUT projects/:id/debian_distributions/:codename' do
let(:method) { :put }
let(:url) { "/projects/#{container.id}/debian_distributions/#{distribution.codename}" }
let(:api_params) { { suite: 'my-suite' } }
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian distributions write endpoint', 'PUT', :success, /^{.*"codename":"existing-codename",.*"suite":"my-suite",/
2021-09-04 01:27:46 +05:30
context 'with invalid parameters' do
let(:api_params) { { suite: distribution.codename } }
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian distributions write endpoint', 'GET', :bad_request, /^{"message":{"suite":\["has already been taken as Codename"\]}}$/
2021-09-04 01:27:46 +05:30
end
end
describe 'DELETE projects/:id/debian_distributions/:codename' do
let(:method) { :delete }
let(:url) { "/projects/#{container.id}/debian_distributions/#{distribution.codename}" }
2023-03-04 22:38:38 +05:30
it_behaves_like 'Debian distributions maintainer write endpoint', 'DELETE', :success, /^{"message":"202 Accepted"}$/
2021-09-04 01:27:46 +05:30
context 'when destroy fails' do
before do
allow_next_found_instance_of(::Packages::Debian::ProjectDistribution) do |distribution|
expect(distribution).to receive(:destroy).and_return(false)
end
end
2021-12-11 22:18:48 +05:30
it_behaves_like 'Debian distributions maintainer write endpoint', 'GET', :bad_request, /^{"message":"Failed to delete distribution"}$/
2021-09-04 01:27:46 +05:30
end
end
end
end