Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions lib/aptly_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,20 @@ def repo_upload(repo_options = { name: nil, dir: nil, file: nil,
case response.code
when 404
puts 'repository with such name does not exist'
return response
end

json_response = JSON.parse(response.body)

unless json_response['FailedFiles'].empty?
begin
rescue StandardError => e
puts "Files that failed to upload... #{json_response['FailedFiles']}"
puts e
end
puts "Files that failed to upload... #{json_response['FailedFiles']}"
end

unless json_response['Report']['Warnings'].empty?
begin
rescue StandardError => e
puts "File upload warning message[s]...\
#{json_response['Report']['Warnings']}"
puts e
end
puts "File upload warning message[s]...\
#{json_response['Report']['Warnings']}"
end

return response
end
end
Expand Down
29 changes: 22 additions & 7 deletions test/test_aptly_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,39 @@ def test_repo_upload
'{"FailedFiles"=>[], "Report"=>{"Warnings"=>[], "Added"=>'\
'["geoipupdate_2.0.0_amd64 added"], "Removed"=>[]}}'
end

def test_repo_upload_repo_does_not_exist
file_api.file_post(file_uri: '/testdir',
package: 'testdir/fixtures/test_1.0_amd64.deb',
local_file: 'test/fixtures/test_1.0_amd64.deb')
assert_output(/repository with such name does not exist/) do
assert_includes(
repo_api.repo_upload(
name: 'repodoesnotexist',
dir: 'testdir/',
file: 'test_1.0_amd64.deb').to_s,
'local repo with name repodoesnotexist not found'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the parameters of a method call if they span more than one line.

)
end
end
end

describe 'API Upload to Repo, failure scenario' do
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:repo_api_fail) { AptlyCli::AptlyRepo.new(config) }
let(:data) do
repo_api_fail.repo_upload(name: 'testrepo',
dir: 'rockpackages',
file: 'test_package_not_here',
noremove: true)
end

def test_repo_upload_fail_response
assert_output(/Files that failed to upload.../) do
@data = repo_api_fail.repo_upload(name: 'testrepo',
dir: 'rockpackages',
file: 'test_package_not_here',
noremove: true)
end
assert_equal '["Unable to process /aptly/upload/'\
'rockpackages/test_package_not_here: stat '\
'/aptly/upload/rockpackages/test_package_not_here: '\
'no such file or directory"]',
data['Report']['Warnings'].to_s
@data['Report']['Warnings'].to_s
end
end

Expand Down