Skip to content

Commit

Permalink
Fixup the existing tests
Browse files Browse the repository at this point in the history
We'll want a few more tests to be added here
  • Loading branch information
tas50 committed Mar 5, 2016
1 parent c49c708 commit 44784c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/ohai/mixin/dmi_decode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def guest_from_dmi(dmi_data)
dmi_data.each_line do |line|
case line
when /Manufacturer: Microsoft/
if dmi_data =~ /Product Name: Virtual Machine/
if dmi_data =~ /Product.*: Virtual Machine/
if dmi_data =~ /Version: (7.0|Hyper-V)/
return "hyperv"
elsif dmi_data =~ /Version: (VS2005R2|6.0)/
Expand Down
18 changes: 10 additions & 8 deletions spec/unit/plugins/solaris2/virtualization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
allow(@plugin).to receive(:collect_os).and_return(:solaris2)

# default to all requested Files not existing
allow(File).to receive(:exists?).with("/usr/sbin/psrinfo").and_return(false)
allow(File).to receive(:exists?).with("/usr/sbin/smbios").and_return(false)
allow(File).to receive(:exists?).with("/usr/sbin/zoneadm").and_return(false)
allow(File).to receive(:exist?).with("/usr/sbin/psrinfo").and_return(false)
allow(File).to receive(:exist?).with("/usr/sbin/smbios").and_return(false)
allow(File).to receive(:exist?).with("/usr/sbin/zoneadm").and_return(false)
allow(@plugin).to receive(:shell_out).with("/usr/sbin/smbios").and_return(mock_shell_out(0, "", ""))
allow(@plugin).to receive(:shell_out).with("#{ Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, "", ""))
end

describe "when we are checking for kvm" do
before(:each) do
expect(File).to receive(:exists?).with("/usr/sbin/psrinfo").and_return(true)
expect(File).to receive(:exist?).with("/usr/sbin/psrinfo").and_return(true)
end

it "should run psrinfo -pv" do
Expand All @@ -52,18 +52,19 @@
@plugin.run
expect(@plugin[:virtualization][:system]).to eq("kvm")
expect(@plugin[:virtualization][:role]).to eq("guest")
expect(@plugin[:virtualization][:systems][:kvm]).to eq("guest")
end

it "should not set virtualization if kvm isn't there" do
expect(@plugin).to receive(:shell_out).with("#{ Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, @psrinfo_pv, ""))
@plugin.run
expect(@plugin[:virtualization]).to eq({})
expect(@plugin[:virtualization][:systems]).to eq({})
end
end

describe "when we are parsing smbios" do
before(:each) do
expect(File).to receive(:exists?).with("/usr/sbin/smbios").and_return(true)
expect(File).to receive(:exist?).with("/usr/sbin/smbios").and_return(true)
end

it "should run smbios" do
Expand Down Expand Up @@ -107,17 +108,18 @@
@plugin.run
expect(@plugin[:virtualization][:system]).to eq("vmware")
expect(@plugin[:virtualization][:role]).to eq("guest")
expect(@plugin[:virtualization][:systems][:vmware]).to eq("guest")
end

it "should run smbios and not set virtualization if nothing is detected" do
expect(@plugin).to receive(:shell_out).with("/usr/sbin/smbios")
@plugin.run
expect(@plugin[:virtualization]).to eq({})
expect(@plugin[:virtualization][:systems]).to eq({})
end
end

it "should not set virtualization if no tests match" do
@plugin.run
expect(@plugin[:virtualization]).to eq({})
expect(@plugin[:virtualization][:systems]).to eq({})
end
end

0 comments on commit 44784c0

Please sign in to comment.