From e09d3422846510e4b26f8725a7579b8aae4ae682 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 5 Jun 2016 19:10:19 -0400 Subject: [PATCH] guests/redhat: Add tests for flavor --- plugins/guests/redhat/cap/flavor.rb | 5 +-- .../plugins/guests/redhat/cap/flavor_test.rb | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test/unit/plugins/guests/redhat/cap/flavor_test.rb diff --git a/plugins/guests/redhat/cap/flavor.rb b/plugins/guests/redhat/cap/flavor.rb index 2ae87201a..8bdda2629 100644 --- a/plugins/guests/redhat/cap/flavor.rb +++ b/plugins/guests/redhat/cap/flavor.rb @@ -5,10 +5,9 @@ module VagrantPlugins def self.flavor(machine) # Read the version file output = "" - machine.communicate.sudo("cat /etc/redhat-release") do |type, data| - output += data if type == :stdout + machine.communicate.sudo("cat /etc/redhat-release") do |_, data| + output = data end - output.chomp! # Detect various flavors we care about if output =~ /(CentOS|Red Hat Enterprise|Scientific) Linux( .+)? release 7/i diff --git a/test/unit/plugins/guests/redhat/cap/flavor_test.rb b/test/unit/plugins/guests/redhat/cap/flavor_test.rb new file mode 100644 index 000000000..636b079cb --- /dev/null +++ b/test/unit/plugins/guests/redhat/cap/flavor_test.rb @@ -0,0 +1,39 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestRedHat::Cap::Flavor" 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 ".flavor" do + let(:cap) { caps.get(:flavor) } + + { + "CentOS Linux 2.4 release 7" => :rhel_7, + "Red Hat Enterprise Linux release 7" => :rhel_7, + "Scientific Linux release 7" => :rhel_7, + + "CentOS" => :rhel, + "RHEL 6" => :rhel, + "banana" => :rhel, + }.each do |str, expected| + it "returns #{expected} for #{str}" do + comm.stub_command("cat /etc/redhat-release", stdout: str) + expect(cap.flavor(machine)).to be(expected) + end + end + end +end