diff --git a/plugins/guests/redhat/cap/rsync.rb b/plugins/guests/redhat/cap/rsync.rb index 8eace63f0..83804191a 100644 --- a/plugins/guests/redhat/cap/rsync.rb +++ b/plugins/guests/redhat/cap/rsync.rb @@ -3,13 +3,13 @@ module VagrantPlugins module Cap class RSync def self.rsync_install(machine) - machine.communicate.tap do |comm| - if VagrantPlugins::GuestRedHat::Plugin.dnf?(machine) - comm.sudo("dnf -y install rsync") + machine.communicate.sudo <<-EOH.gsub(/^ {12}/, '') + if command -v dnf; then + dnf -y install rsync else - comm.sudo("yum -y install rsync") - end - end + yum -y install rsync + fi + EOH end end end diff --git a/test/unit/plugins/guests/redhat/cap/rsync_test.rb b/test/unit/plugins/guests/redhat/cap/rsync_test.rb new file mode 100644 index 000000000..654af9344 --- /dev/null +++ b/test/unit/plugins/guests/redhat/cap/rsync_test.rb @@ -0,0 +1,29 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestRedHat::Cap:RSync" do + let(:caps) do + VagrantPlugins::GuestRedHat::Plugin + .components + .guest_capabilities[:redhat] + 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 ".rsync_install" do + let(:cap) { caps.get(:rsync_install) } + + it "installs rsync" do + cap.rsync_install(machine) + expect(comm.received_commands[0]).to match(/install rsync/) + end + end +end