Additional fixes + tests for shell expansion [GH-633]
This commit is contained in:
parent
9a242ba718
commit
f0b77d2f30
|
@ -6,7 +6,7 @@ module Vagrant
|
||||||
# simply does a file copy.
|
# simply does a file copy.
|
||||||
class File < Base
|
class File < Base
|
||||||
def self.match?(uri)
|
def self.match?(uri)
|
||||||
::File.exists?(uri)
|
::File.file?(::File.expand_path(uri))
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare(source_url)
|
def prepare(source_url)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
require File.expand_path("../../../base", __FILE__)
|
require File.expand_path("../../../base", __FILE__)
|
||||||
|
|
||||||
|
require "tempfile"
|
||||||
|
|
||||||
describe Vagrant::Downloaders::File do
|
describe Vagrant::Downloaders::File do
|
||||||
let(:ui) { double("ui") }
|
let(:ui) { double("ui") }
|
||||||
let(:instance) { described_class.new(ui) }
|
let(:instance) { described_class.new(ui) }
|
||||||
|
@ -12,6 +14,23 @@ describe Vagrant::Downloaders::File do
|
||||||
it "should not match non-existent files" do
|
it "should not match non-existent files" do
|
||||||
described_class.match?(File.join(__FILE__, "nowaywaywaywayayway")).should_not be
|
described_class.match?(File.join(__FILE__, "nowaywaywaywayayway")).should_not be
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should match files where the path needs to be expanded" do
|
||||||
|
old_home = ENV["HOME"]
|
||||||
|
begin
|
||||||
|
# Create a temporary file
|
||||||
|
temp = Tempfile.new("vagrant")
|
||||||
|
|
||||||
|
# Set our home directory to be this directory so we can use
|
||||||
|
# "~" paths
|
||||||
|
ENV["HOME"] = File.dirname(temp.path)
|
||||||
|
|
||||||
|
# Test that we can find the temp file
|
||||||
|
described_class.match?("~/#{File.basename(temp.path)}").should be
|
||||||
|
ensure
|
||||||
|
ENV["HOME"] = old_home
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "preparing" do
|
describe "preparing" do
|
||||||
|
@ -28,6 +47,24 @@ describe Vagrant::Downloaders::File do
|
||||||
|
|
||||||
expect { instance.prepare(path) }.to raise_error(Vagrant::Errors::DownloaderFileDoesntExist)
|
expect { instance.prepare(path) }.to raise_error(Vagrant::Errors::DownloaderFileDoesntExist)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should find files that use shell expansions" do
|
||||||
|
old_home = ENV["HOME"]
|
||||||
|
begin
|
||||||
|
# Create a temporary file
|
||||||
|
temp = Tempfile.new("vagrant")
|
||||||
|
|
||||||
|
# Set our home directory to be this directory so we can use
|
||||||
|
# "~" paths
|
||||||
|
ENV["HOME"] = File.dirname(temp.path)
|
||||||
|
|
||||||
|
# Test that we can find the temp file
|
||||||
|
expect { instance.prepare("~/#{File.basename(temp.path)}") }.
|
||||||
|
to_not raise_error
|
||||||
|
ensure
|
||||||
|
ENV["HOME"] = old_home
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "downloading" do
|
describe "downloading" do
|
||||||
|
|
Loading…
Reference in New Issue