Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d77ca7e8
Commit
d77ca7e8
authored
Oct 20, 2020
by
Mathieu Parent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Packages::Debian::CreatePackageFileService
parent
f10e7bcf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
142 additions
and
0 deletions
+142
-0
app/services/packages/debian/create_package_file_service.rb
app/services/packages/debian/create_package_file_service.rb
+36
-0
spec/services/packages/debian/create_package_file_service_spec.rb
...vices/packages/debian/create_package_file_service_spec.rb
+106
-0
No files found.
app/services/packages/debian/create_package_file_service.rb
0 → 100644
View file @
d77ca7e8
# frozen_string_literal: true
module
Packages
module
Debian
class
CreatePackageFileService
def
initialize
(
package
,
params
)
@package
=
package
@params
=
params
end
def
execute
raise
ArgumentError
,
"Invalid package"
unless
package
.
present?
# Debian package file are first uploaded to incoming with empty metadata,
# and are moved later by Packages::Debian::ProcessChangesService
package
.
package_files
.
create!
(
file:
params
[
:file
],
size:
params
[
:file
]
&
.
size
,
file_name:
params
[
:file_name
],
file_sha1:
params
[
:file_sha1
],
file_sha256:
params
[
:file
]
&
.
sha256
,
file_md5:
params
[
:file_md5
],
debian_file_metadatum_attributes:
{
file_type:
'unknown'
,
architecture:
nil
,
fields:
nil
}
)
end
private
attr_reader
:package
,
:params
end
end
end
spec/services/packages/debian/create_package_file_service_spec.rb
0 → 100644
View file @
d77ca7e8
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Packages
::
Debian
::
CreatePackageFileService
do
include
WorkhorseHelpers
let_it_be
(
:package
)
{
create
(
:debian_incoming
,
without_package_files:
true
)
}
describe
'#execute'
do
let
(
:file_name
)
{
'libsample0_1.2.3~alpha2_amd64.deb'
}
let
(
:fixture_path
)
{
"spec/fixtures/packages/debian/
#{
file_name
}
"
}
let
(
:params
)
do
{
file:
file
,
file_name:
file_name
,
file_sha1:
'54321'
,
file_md5:
'12345'
}.
with_indifferent_access
end
let
(
:service
)
{
described_class
.
new
(
package
,
params
)
}
subject
(
:package_file
)
{
service
.
execute
}
shared_examples
'a valid deb'
do
it
'creates a new package file'
,
:aggregate_failures
do
expect
(
package_file
).
to
be_valid
expect
(
package_file
.
file
.
read
).
to
start_with
(
'!<arch>'
)
expect
(
package_file
.
size
).
to
eq
(
1124
)
expect
(
package_file
.
file_name
).
to
eq
(
file_name
)
expect
(
package_file
.
file_sha1
).
to
eq
(
'54321'
)
expect
(
package_file
.
file_sha256
).
to
eq
(
'543212345'
)
expect
(
package_file
.
file_md5
).
to
eq
(
'12345'
)
expect
(
package_file
.
debian_file_metadatum
).
to
be_valid
expect
(
package_file
.
debian_file_metadatum
.
file_type
).
to
eq
(
'unknown'
)
expect
(
package_file
.
debian_file_metadatum
.
architecture
).
to
be_nil
expect
(
package_file
.
debian_file_metadatum
.
fields
).
to
be_nil
end
end
context
'with temp file'
do
let!
(
:file
)
do
upload_path
=
::
Packages
::
PackageFileUploader
.
workhorse_local_upload_path
file_path
=
upload_path
+
'/'
+
file_name
FileUtils
.
mkdir_p
(
upload_path
)
File
.
write
(
file_path
,
File
.
read
(
fixture_path
))
UploadedFile
.
new
(
file_path
,
filename:
File
.
basename
(
file_path
),
sha256:
'543212345'
)
end
it_behaves_like
'a valid deb'
end
context
'with remote file'
do
let!
(
:fog_connection
)
do
stub_package_file_object_storage
(
direct_upload:
true
)
end
before
do
allow_next_instance_of
(
UploadedFile
)
do
|
uploaded_file
|
allow
(
uploaded_file
).
to
receive
(
:sha256
).
and_return
(
'543212345'
)
end
end
let
(
:tmp_object
)
do
fog_connection
.
directories
.
new
(
key:
'packages'
).
files
.
create
(
# rubocop:disable Rails/SaveBang
key:
"tmp/uploads/
#{
file_name
}
"
,
body:
File
.
read
(
fixture_path
)
)
end
let!
(
:file
)
{
fog_to_uploaded_file
(
tmp_object
)
}
it_behaves_like
'a valid deb'
end
context
'package is missing'
do
let
(
:package
)
{
nil
}
let
(
:params
)
{
{}
}
it
'raises an error'
do
expect
{
subject
.
execute
}.
to
raise_error
(
ArgumentError
,
'Invalid package'
)
end
end
context
'params is empty'
do
let
(
:params
)
{
{}
}
it
'raises an error'
do
expect
{
subject
.
execute
}.
to
raise_error
(
ActiveRecord
::
RecordInvalid
)
end
end
context
'file is missing'
do
let
(
:file_name
)
{
'libsample0_1.2.3~alpha2_amd64.deb'
}
let
(
:file
)
{
nil
}
it
'raises an error'
do
expect
{
subject
.
execute
}.
to
raise_error
(
ActiveRecord
::
RecordInvalid
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment