summaryrefslogtreecommitdiff
path: root/spec/services/packages
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/packages')
-rw-r--r--spec/services/packages/composer/create_package_service_spec.rb10
-rw-r--r--spec/services/packages/conan/create_package_service_spec.rb10
-rw-r--r--spec/services/packages/maven/create_package_service_spec.rb4
-rw-r--r--spec/services/packages/npm/create_package_service_spec.rb13
-rw-r--r--spec/services/packages/nuget/create_package_service_spec.rb7
-rw-r--r--spec/services/packages/pypi/create_package_service_spec.rb18
6 files changed, 52 insertions, 10 deletions
diff --git a/spec/services/packages/composer/create_package_service_spec.rb b/spec/services/packages/composer/create_package_service_spec.rb
index 3f9da31cf6e..a1fe9a1b918 100644
--- a/spec/services/packages/composer/create_package_service_spec.rb
+++ b/spec/services/packages/composer/create_package_service_spec.rb
@@ -37,12 +37,16 @@ RSpec.describe Packages::Composer::CreatePackageService do
expect(created_package.composer_metadatum.target_sha).to eq branch.target
expect(created_package.composer_metadatum.composer_json.to_json).to eq json
end
+
+ it_behaves_like 'assigns the package creator' do
+ let(:package) { created_package }
+ end
end
context 'with a tag' do
let(:tag) { project.repository.find_tag('v1.2.3') }
- before do
+ before(:all) do
project.repository.add_tag(user, 'v1.2.3', 'master')
end
@@ -54,6 +58,10 @@ RSpec.describe Packages::Composer::CreatePackageService do
expect(created_package.name).to eq package_name
expect(created_package.version).to eq '1.2.3'
end
+
+ it_behaves_like 'assigns the package creator' do
+ let(:package) { created_package }
+ end
end
end
diff --git a/spec/services/packages/conan/create_package_service_spec.rb b/spec/services/packages/conan/create_package_service_spec.rb
index f8068f6e57b..b217e570aba 100644
--- a/spec/services/packages/conan/create_package_service_spec.rb
+++ b/spec/services/packages/conan/create_package_service_spec.rb
@@ -5,9 +5,11 @@ RSpec.describe Packages::Conan::CreatePackageService do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
- subject { described_class.new(project, user, params) }
+ subject(:service) { described_class.new(project, user, params) }
describe '#execute' do
+ subject(:package) { service.execute }
+
context 'valid params' do
let(:params) do
{
@@ -19,8 +21,6 @@ RSpec.describe Packages::Conan::CreatePackageService do
end
it 'creates a new package' do
- package = subject.execute
-
expect(package).to be_valid
expect(package.name).to eq(params[:package_name])
expect(package.version).to eq(params[:package_version])
@@ -28,6 +28,8 @@ RSpec.describe Packages::Conan::CreatePackageService do
expect(package.conan_metadatum.package_username).to eq(params[:package_username])
expect(package.conan_metadatum.package_channel).to eq(params[:package_channel])
end
+
+ it_behaves_like 'assigns the package creator'
end
context 'invalid params' do
@@ -41,7 +43,7 @@ RSpec.describe Packages::Conan::CreatePackageService do
end
it 'fails' do
- expect { subject.execute }.to raise_exception(ActiveRecord::RecordInvalid)
+ expect { package }.to raise_exception(ActiveRecord::RecordInvalid)
end
end
end
diff --git a/spec/services/packages/maven/create_package_service_spec.rb b/spec/services/packages/maven/create_package_service_spec.rb
index bfdf62008ba..7ec368aa00f 100644
--- a/spec/services/packages/maven/create_package_service_spec.rb
+++ b/spec/services/packages/maven/create_package_service_spec.rb
@@ -34,6 +34,8 @@ RSpec.describe Packages::Maven::CreatePackageService do
end
it_behaves_like 'assigns build to package'
+
+ it_behaves_like 'assigns the package creator'
end
context 'without version' do
@@ -57,6 +59,8 @@ RSpec.describe Packages::Maven::CreatePackageService do
expect(package.maven_metadatum.app_name).to eq(app_name)
expect(package.maven_metadatum.app_version).to be nil
end
+
+ it_behaves_like 'assigns the package creator'
end
context 'path is missing' do
diff --git a/spec/services/packages/npm/create_package_service_spec.rb b/spec/services/packages/npm/create_package_service_spec.rb
index c1391746f52..c8431c640da 100644
--- a/spec/services/packages/npm/create_package_service_spec.rb
+++ b/spec/services/packages/npm/create_package_service_spec.rb
@@ -27,6 +27,10 @@ RSpec.describe Packages::Npm::CreatePackageService do
.and change { Packages::Tag.count }.by(1)
end
+ it_behaves_like 'assigns the package creator' do
+ let(:package) { subject }
+ end
+
it { is_expected.to be_valid }
it 'creates a package with name and version' do
@@ -61,6 +65,15 @@ RSpec.describe Packages::Npm::CreatePackageService do
it { expect(subject[:message]).to be 'Package already exists.' }
end
+ context 'file size above maximum limit' do
+ before do
+ params['_attachments']["#{package_name}-#{version}.tgz"]['length'] = project.actual_limits.npm_max_file_size + 1
+ end
+
+ it { expect(subject[:http_status]).to eq 400 }
+ it { expect(subject[:message]).to be 'File is too large.' }
+ end
+
context 'with incorrect namespace' do
let(:package_name) { '@my_other_namespace/my-app' }
diff --git a/spec/services/packages/nuget/create_package_service_spec.rb b/spec/services/packages/nuget/create_package_service_spec.rb
index 1579b42d9ad..e51bc03f311 100644
--- a/spec/services/packages/nuget/create_package_service_spec.rb
+++ b/spec/services/packages/nuget/create_package_service_spec.rb
@@ -9,9 +9,10 @@ RSpec.describe Packages::Nuget::CreatePackageService do
describe '#execute' do
subject { described_class.new(project, user, params).execute }
+ let(:package) { Packages::Package.last }
+
it 'creates the package' do
expect { subject }.to change { Packages::Package.count }.by(1)
- package = Packages::Package.last
expect(package).to be_valid
expect(package.name).to eq(Packages::Nuget::CreatePackageService::TEMPORARY_PACKAGE_NAME)
@@ -23,12 +24,12 @@ RSpec.describe Packages::Nuget::CreatePackageService do
expect { subject }.to change { Packages::Package.count }.by(1)
expect { described_class.new(project, user, params).execute }.to change { Packages::Package.count }.by(1)
- package = Packages::Package.last
-
expect(package).to be_valid
expect(package.name).to eq(Packages::Nuget::CreatePackageService::TEMPORARY_PACKAGE_NAME)
expect(package.version).to start_with(Packages::Nuget::CreatePackageService::PACKAGE_VERSION)
expect(package.package_type).to eq('nuget')
end
+
+ it_behaves_like 'assigns the package creator'
end
end
diff --git a/spec/services/packages/pypi/create_package_service_spec.rb b/spec/services/packages/pypi/create_package_service_spec.rb
index bfecb32f9ef..c985c1e54ea 100644
--- a/spec/services/packages/pypi/create_package_service_spec.rb
+++ b/spec/services/packages/pypi/create_package_service_spec.rb
@@ -6,12 +6,14 @@ RSpec.describe Packages::Pypi::CreatePackageService do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
- let_it_be(:params) do
+
+ let(:requires_python) { '>=2.7' }
+ let(:params) do
{
name: 'foo',
version: '1.0',
content: temp_file('foo.tgz'),
- requires_python: '>=2.7',
+ requires_python: requires_python,
sha256_digest: '123',
md5_digest: '567'
}
@@ -37,6 +39,18 @@ RSpec.describe Packages::Pypi::CreatePackageService do
end
end
+ context 'with an invalid metadata' do
+ let(:requires_python) { 'x' * 256 }
+
+ it 'raises an error' do
+ expect { subject }.to raise_error(ActiveRecord::RecordInvalid)
+ end
+ end
+
+ it_behaves_like 'assigns the package creator' do
+ let(:package) { created_package }
+ end
+
context 'with an existing package' do
before do
described_class.new(project, user, params).execute