guests/redhat: Add tests for flavor

This commit is contained in:
Seth Vargo 2016-06-05 19:10:19 -04:00
parent cc26c46066
commit e09d342284
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
2 changed files with 41 additions and 3 deletions

View File

@ -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

View File

@ -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