Skip to content

Commit

Permalink
Raise error if using GitHub releases & repository not in Cargo.toml
Browse files Browse the repository at this point in the history
Fixes #18.
  • Loading branch information
malept committed Jan 9, 2017
1 parent 63c8a57 commit 934645d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

* Raise error if using GitHub Releases & repository not in `Cargo.toml` (#18)

## [0.8.0] - 2016-12-05

### Added
Expand Down
10 changes: 8 additions & 2 deletions lib/thermite/github_release_binary.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true
#
# Copyright (c) 2016 Mark Lee and contributors
# Copyright (c) 2016, 2017 Mark Lee and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
# associated documentation files (the "Software"), to deal in the Software without restriction,
Expand Down Expand Up @@ -83,7 +83,13 @@ def download_latest_binary_from_github_release
end

def github_uri
@github_uri ||= config.toml[:package][:repository]
@github_uri ||= begin
unless (repository = config.toml[:package][:repository])
raise KeyError, 'No repository found in Config.toml'
end

repository
end
end

def github_download_uri(tag, version)
Expand Down
43 changes: 41 additions & 2 deletions test/lib/thermite/github_release_binary_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true
#
# Copyright (c) 2016, 2017 Mark Lee and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
# associated documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

require 'tmpdir'
require 'test_helper'
require 'thermite/github_release_binary'
Expand Down Expand Up @@ -51,17 +71,36 @@ def test_download_cargo_version_from_github_release_with_custom_git_tag_format
assert mock_module.download_binary_from_github_release
end

def test_download_cargo_version_from_github_release_with_client_error
def test_download_cargo_version_from_github_release_with_no_repository
mock_module(github_releases: true)
mock_module.config.stubs(:toml).returns(package: { version: '4.5.6' })

assert_raises KeyError do
mock_module.download_binary_from_github_release
end
end

def test_download_cargo_version_from_github_release_with_client_error
mock_module(github_releases: true)
mock_module.config.stubs(:toml).returns(
package: {
repository: 'test/test',
version: '4.5.6'
}
)
Net::HTTP.stubs(:get_response).returns(Net::HTTPClientError.new('1.1', 403, 'Forbidden'))

assert !mock_module.download_binary_from_github_release
end

def test_download_cargo_version_from_github_release_with_server_error
mock_module(github_releases: true)
mock_module.config.stubs(:toml).returns(package: { version: '4.5.6' })
mock_module.config.stubs(:toml).returns(
package: {
repository: 'test/test',
version: '4.5.6'
}
)
server_error = Net::HTTPServerError.new('1.1', 500, 'Internal Server Error')
Net::HTTP.stubs(:get_response).returns(server_error)

Expand Down

0 comments on commit 934645d

Please sign in to comment.