-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from borsothy/GithubDownloadErrorHandling
Improved error handling in 'download_from_github'
- Loading branch information
Showing
3 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
spec/moonshot/artifact_repository/s3_bucket_via_github_releases_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require 'fakefs/spec_helpers' | ||
|
||
module Moonshot | ||
describe ArtifactRepository::S3BucketViaGithubReleases do | ||
let(:version) { '0.0.0'} | ||
let(:bucket_name) { 'moonshot-test-bucket' } | ||
let(:artifact_name) { "moonshot-#{version}-beta.tar.gz" } | ||
let(:hub_command) { "hub release download #{version}" } | ||
|
||
def fake_artifact | ||
FakeFS { FileUtils.touch(artifact_name) } | ||
end | ||
|
||
def fake_checksum_file | ||
FakeFS do | ||
base = File.basename(artifact_name, '.tar.gz') | ||
FileUtils.touch("#{base}.md5") | ||
end | ||
end | ||
|
||
subject { described_class.new(bucket_name) } | ||
|
||
describe '#download_from_github' do | ||
include FakeFS::SpecHelpers | ||
|
||
it 'should use hub to download the latest version' do | ||
obj = subject | ||
expect(obj).to receive(:sh_out) { fake_artifact }.with(hub_command) | ||
|
||
subject.send(:download_from_github, version) | ||
end | ||
|
||
it 'should raise RuntimeError when download has failed' do | ||
obj = subject | ||
expect(obj).to receive(:sh_out).at_least(:once) | ||
|
||
expect do | ||
obj.send(:download_from_github, version) | ||
end.to raise_error(RuntimeError) | ||
end | ||
|
||
it 'should retry if the download has failed' do | ||
obj = subject | ||
expect(obj).to receive(:sh_out).with(hub_command).exactly(3).times | ||
|
||
expect { obj.send(:download_from_github, version) }.to raise_error(RuntimeError) | ||
end | ||
|
||
it 'should verify the checksum of the downloaded artifact' do | ||
obj = subject | ||
|
||
expect(obj).to receive(:sh_out) do | ||
fake_artifact | ||
fake_checksum_file | ||
end.with(hub_command) | ||
|
||
expect(obj).to receive(:verify_download_checksum) | ||
obj.send(:download_from_github, version) | ||
end | ||
|
||
it 'should return the name of the downloaded artifact' do | ||
obj = subject | ||
|
||
allow(obj).to receive(:sh_out) { fake_artifact }.with(hub_command) | ||
|
||
expect(obj.send(:download_from_github, version))\ | ||
.to eql("/#{artifact_name}") | ||
end | ||
end | ||
end | ||
end |