diff --git a/plugins/guests/freebsd/cap/mount_nfs_folder.rb b/plugins/guests/freebsd/cap/mount_nfs_folder.rb index 58d8f785c..1541eff33 100644 --- a/plugins/guests/freebsd/cap/mount_nfs_folder.rb +++ b/plugins/guests/freebsd/cap/mount_nfs_folder.rb @@ -3,17 +3,20 @@ module VagrantPlugins module Cap class MountNFSFolder def self.mount_nfs_folder(machine, ip, folders) - folders.each do |name, opts| + comm = machine.communicate + + commands = [] + + folders.each do |_, opts| if opts[:nfs_version] - nfs_version_mount_option="-o nfsv#{opts[:nfs_version]}" + mount_opts = "-o nfsv#{opts[:nfs_version]}" end - machine.communicate.sudo("mkdir -p #{opts[:guestpath]}", {shell: "sh"}) - - machine.communicate.sudo( - "mount -t nfs #{nfs_version_mount_option} " + - "'#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'", {shell: "sh"}) + commands << "mkdir -p '#{opts[:guestpath]}'" + commands << "mount -t nfs #{mount_opts} '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'" end + + comm.sudo(commands.join("\n"), { shell: "sh" }) end end end diff --git a/test/unit/plugins/guests/freebsd/cap/mount_nfs_folder_test.rb b/test/unit/plugins/guests/freebsd/cap/mount_nfs_folder_test.rb new file mode 100644 index 000000000..b86ad26df --- /dev/null +++ b/test/unit/plugins/guests/freebsd/cap/mount_nfs_folder_test.rb @@ -0,0 +1,53 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestFreeBSD::Cap::MountNFSFolder" do + let(:described_class) do + VagrantPlugins::GuestFreeBSD::Plugin + .components + .guest_capabilities[:freebsd] + .get(:mount_nfs_folder) + end + + let(:machine) { double("machine") } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + after do + comm.verify_expectations! + end + + describe ".mount_nfs_folder" do + let(:ip) { "1.2.3.4" } + + it "mounts the folder" do + folders = { + "/vagrant-nfs" => { + type: :nfs, + guestpath: "/guest", + hostpath: "/host", + } + } + described_class.mount_nfs_folder(machine, ip, folders) + + expect(comm.received_commands[0]).to match(/mkdir -p '\/guest'/) + expect(comm.received_commands[0]).to match(/'1.2.3.4:\/host' '\/guest'/) + end + + it "mounts with options" do + folders = { + "/vagrant-nfs" => { + type: :nfs, + guestpath: "/guest", + hostpath: "/host", + nfs_version: 2, + } + } + described_class.mount_nfs_folder(machine, ip, folders) + + expect(comm.received_commands[0]).to match(/mount -t nfs -o nfsv2/) + end + end +end