Modify URL fetcher to accept URI (#3633)

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
This commit is contained in:
Jerry Aldrich 2018-12-12 10:05:51 -08:00 committed by Clinton Wolfe
parent 671e315d93
commit 8019b2c487
2 changed files with 11 additions and 2 deletions

View file

@ -24,6 +24,8 @@ module Fetchers
resolve_from_string(target[:url], opts, target[:username], target[:password])
elsif target.is_a?(String)
resolve_from_string(target, opts)
elsif target.is_a?(URI)
resolve_from_string(target.to_s, opts)
end
end
@ -94,8 +96,8 @@ module Fetchers
attr_reader :files, :archive_path
def initialize(url, opts)
@target = url
@target_uri = parse_uri(@target)
@target = url.to_s
@target_uri = url.is_a?(URI) ? url : parse_uri(url)
@insecure = opts['insecure']
@token = opts['token']
@config = opts

View file

@ -34,7 +34,14 @@ describe Fetchers::Url do
res.expects(:open).returns(mock_open)
_(res).must_be_kind_of Fetchers::Url
_(res.resolved_source).must_equal({url: 'https://chef.io/some.tar.gz', sha256: expected_shasum})
end
it 'handles an https URI' do
uri = URI.parse('https://chef.io/some.tar.gz')
res = Fetchers::Url.resolve(uri)
res.expects(:open).returns(mock_open)
_(res).must_be_kind_of Fetchers::Url
_(res.resolved_source).must_equal({url: 'https://chef.io/some.tar.gz', sha256: expected_shasum})
end
it 'doesnt handle other schemas' do