From 9771c8bd52839e547f459a855773212921d8934c Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Sat, 1 Feb 2014 00:31:01 -0300 Subject: [PATCH] provisioners/file: Add unit tests for the config --- .../plugins/provisioners/file/config_test.rb | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 test/unit/plugins/provisioners/file/config_test.rb diff --git a/test/unit/plugins/provisioners/file/config_test.rb b/test/unit/plugins/provisioners/file/config_test.rb new file mode 100644 index 000000000..e41cac966 --- /dev/null +++ b/test/unit/plugins/provisioners/file/config_test.rb @@ -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