summaryrefslogtreecommitdiffstats
path: root/spec/unit/physicalprocessorcount_spec.rb
diff options
context:
space:
mode:
authorAdrien Thebo <adrien@puppetlabs.com>2011-03-15 17:29:19 -0700
committerAdrien Thebo <adrien.thebo@gmail.com>2011-04-01 18:20:00 -0700
commitc2ff8330f4d705ded3f251e170df4bd973af3d43 (patch)
tree262ac8d76a07fc9217f937daa0c4484027cffebe /spec/unit/physicalprocessorcount_spec.rb
parent0c4a98b2271ed5d84f2aa8783398f08502b578ee (diff)
downloadfacter-c2ff8330f4d705ded3f251e170df4bd973af3d43.tar.gz
facter-c2ff8330f4d705ded3f251e170df4bd973af3d43.tar.xz
facter-c2ff8330f4d705ded3f251e170df4bd973af3d43.zip
(#5135) Refactored physicalprocessorcount
- Refactored code to make testing simpler
Diffstat (limited to 'spec/unit/physicalprocessorcount_spec.rb')
-rw-r--r--spec/unit/physicalprocessorcount_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/unit/physicalprocessorcount_spec.rb b/spec/unit/physicalprocessorcount_spec.rb
new file mode 100644
index 0000000..260788b
--- /dev/null
+++ b/spec/unit/physicalprocessorcount_spec.rb
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+require 'facter'
+
+describe "Physical processor count facts" do
+ before do
+ Facter.loadfacts
+ end
+ before do
+ Facter.clear
+ end
+ it "should return one physical CPU" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
+ Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns("/sys/devices/system/cpu/cpu0/topology/physical_package_id")
+ Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
+
+ Facter.fact(:physicalprocessorcount).value.should == 1
+ end
+
+ it "should return four physical CPUs" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
+ Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(%w{
+ /sys/devices/system/cpu/cpu0/topology/physical_package_id
+ /sys/devices/system/cpu/cpu1/topology/physical_package_id
+ /sys/devices/system/cpu/cpu2/topology/physical_package_id
+ /sys/devices/system/cpu/cpu3/topology/physical_package_id
+ })
+
+ Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
+ Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu1/topology/physical_package_id").returns("1")
+ Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu2/topology/physical_package_id").returns("2")
+ Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu3/topology/physical_package_id").returns("3")
+
+ Facter.fact(:physicalprocessorcount).value.should == 4
+ end
+end