provisioners/file: Add unit tests for the config

This commit is contained in:
Teemu Matilainen 2014-02-01 00:31:01 -03:00
parent 24a03de8bf
commit 9771c8bd52
1 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,71 @@
require_relative "../../../base"
require Vagrant.source_root.join("plugins/provisioners/file/config")
describe VagrantPlugins::FileUpload::Config do
include_context "unit"
subject { described_class.new }
let(:machine) { double("machine") }
describe "#validate" do
it "returns an error if destination is not specified" do
existing_file = File.expand_path(__FILE__)
subject.source = existing_file
subject.finalize!
result = subject.validate(machine)
expect(result["File provisioner"]).to eql([
I18n.t("vagrant.provisioners.file.no_dest_file")
])
end
it "returns an error if source is not specified" do
subject.destination = "/tmp/foo"
subject.finalize!
result = subject.validate(machine)
expect(result["File provisioner"]).to eql([
I18n.t("vagrant.provisioners.file.no_source_file")
])
end
it "returns an error if source file does not exist" do
non_existing_file = "this/does/not/exist"
subject.source = non_existing_file
subject.destination = "/tmp/foo"
subject.finalize!
result = subject.validate(machine)
expect(result["File provisioner"]).to eql([
I18n.t("vagrant.provisioners.file.path_invalid",
path: File.expand_path(non_existing_file))
])
end
it "passes with absolute source path" do
existing_absolute_path = File.expand_path(__FILE__)
subject.source = existing_absolute_path
subject.destination = "/tmp/foo"
subject.finalize!
result = subject.validate(machine)
expect(result["File provisioner"]).to eql([])
end
it "passes with relative source path" do
existing_relative_path = __FILE__
subject.source = existing_relative_path
subject.destination = "/tmp/foo"
subject.finalize!
result = subject.validate(machine)
expect(result["File provisioner"]).to eql([])
end
end
end