spec/unit/util/virtual_spec.rb in facter-1.7.0.rc1 vs spec/unit/util/virtual_spec.rb in facter-1.7.0.rc2
- old
+ new
@@ -56,10 +56,18 @@
it "should not identify Solaris zones when global zone" do
Facter::Util::Resolution.stubs(:exec).with("/sbin/zonename").returns("global")
Facter::Util::Virtual.should_not be_zone
end
+ it "(#14522) handles the unencoded binary data in /proc/self/status on Solaris" do
+ Facter.fact(:osfamily).stubs(:value).returns("Solaris")
+ File.stubs(:open).with('/proc/self/status', 'rb').returns(solaris_proc_self_status)
+ FileTest.stubs(:exists?).with('/proc/self/status').returns(true)
+
+ Facter::Util::Virtual.vserver?.should eq(false)
+ end
+
it "should not detect vserver if no self status" do
FileTest.stubs(:exists?).with("/proc/self/status").returns(false)
Facter::Util::Virtual.should_not be_vserver
end
@@ -232,7 +240,41 @@
# Fake files are always hard to stub. :/
File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").
returns("HP-Oracle-Sun-VMWare-funky-town")
Facter::Util::Virtual.should_not be_virtualbox
+ end
+
+ let :solaris_proc_self_status do
+ sample_data = my_fixture_read('solaris10_proc_self_status1')
+ mockfile = mock('File')
+ mockfile.stubs(:read).returns(sample_data)
+ mockfile
+ end
+
+ shared_examples_for "virt-what" do |kernel, path, null_device|
+ Facter.fact(:kernel).stubs(:value).returns(kernel)
+ Facter::Util::Resolution.expects(:which).with("virt-what").returns(path)
+ Facter::Util::Resolution.expects(:exec).with("#{path} 2>#{null_device}")
+ Facter::Util::Virtual.virt_what
+ end
+
+ context "on linux" do
+ it_should_behave_like "virt-what", "linux", "/usr/bin/virt-what", "/dev/null"
+
+ it "should strip out warnings on stdout from virt-what" do
+ virt_what_warning = "virt-what: this script must be run as root"
+ Facter.fact(:kernel).stubs(:value).returns('linux')
+ Facter::Util::Resolution.expects(:which).with('virt-what').returns "/usr/bin/virt-what"
+ Facter::Util::Resolution.expects(:exec).with('/usr/bin/virt-what 2>/dev/null').returns virt_what_warning
+ Facter::Util::Virtual.virt_what.should_not match /^virt-what: /
+ end
+ end
+
+ context "on unix" do
+ it_should_behave_like "virt-what", "unix", "/usr/bin/virt-what", "/dev/null"
+ end
+
+ context "on windows" do
+ it_should_behave_like "virt-what", "windows", 'c:\windows\system32\virt-what', "NUL"
end
end