[Pkg-puppet-devel] [facter] 32/352: (maint) Simplify processor_spec sysfs stubbing

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:28 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit dec6f7d876bdd33c0eb317d2942cf9f371561045
Author: Adrien Thebo <git at somethingsinistral.net>
Date:   Wed May 22 11:19:40 2013 -0700

    (maint) Simplify processor_spec sysfs stubbing
    
    Conflicts:
    	spec/unit/processor_spec.rb
---
 spec/unit/processor_spec.rb | 69 +++++++++++++--------------------------------
 1 file changed, 19 insertions(+), 50 deletions(-)

diff --git a/spec/unit/processor_spec.rb b/spec/unit/processor_spec.rb
index 200afbf..6dad114 100755
--- a/spec/unit/processor_spec.rb
+++ b/spec/unit/processor_spec.rb
@@ -147,20 +147,32 @@ describe "Processor facts" do
 
     it_behaves_like 'a /proc/cpuinfo based processor fact', :processorcount
 
+    def sysfs_cpu_stubs(count)
+      (0...count).map { |index| "/sys/devices/system/cpu/cpu#{index}" }
+    end
+
     describe 'when /proc/cpuinfo returns 0 processors (#2945)' do
       include_context 'Linux processor stubs'
+
       before do
         File.stubs(:readlines).with("/proc/cpuinfo").returns([])
+        File.stubs(:exists?).with("/sys/devices/system/cpu").returns(true)
+      end
+
+      it "should be 2 via sysfs when cpu0 and cpu1 are present" do
+        Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(
+          sysfs_cpu_stubs(2)
+        )
+
+        Facter.fact(:processorcount).value.should == "2"
       end
 
-      it 'enumerates sysfs for the processorcount' do
-        File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
-        Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(%w{
-          /sys/devices/system/cpu/cpu0
-          /sys/devices/system/cpu/cpu1
-        })
+      it "should be 16 via sysfs when cpu0 through cpu15 are present" do
+        Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(
+          sysfs_cpu_stubs(16)
+        )
 
-        Facter.fact(:processorcount).value.should == '2'
+        Facter.fact(:processorcount).value.should == "16"
       end
     end
   end
@@ -199,55 +211,12 @@ describe "Processor facts" do
       Facter.fact(:processor).value.should == "SomeVendor CPU 3GHz"
     end
 
-
     it "should be 2 on dual-processor DragonFly box" do
       Facter.fact(:kernel).stubs(:value).returns("DragonFly")
       Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
 
       Facter.fact(:processorcount).value.should == "2"
     end
-
-    it "should be 2 via sysfs when cpu0 and cpu1 are present" do
-      Facter.fact(:kernel).stubs(:value).returns("Linux")
-      File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
-      ## sysfs method is only used if cpuinfo method returned no processors
-      File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
-      File.stubs(:readlines).with("/proc/cpuinfo").returns([])
-      Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(%w{
-        /sys/devices/system/cpu/cpu0
-        /sys/devices/system/cpu/cpu1
-      })
-
-      Facter.fact(:processorcount).value.should == "2"
-    end
-
-    it "should be 16 via sysfs when cpu0 through cpu15 are present" do
-      Facter.fact(:kernel).stubs(:value).returns("Linux")
-      File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
-      ## sysfs method is only used if cpuinfo method returned no processors
-      File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
-      File.stubs(:readlines).with("/proc/cpuinfo").returns([])
-      Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(%w{
-        /sys/devices/system/cpu/cpu0
-        /sys/devices/system/cpu/cpu1
-        /sys/devices/system/cpu/cpu2
-        /sys/devices/system/cpu/cpu3
-        /sys/devices/system/cpu/cpu4
-        /sys/devices/system/cpu/cpu5
-        /sys/devices/system/cpu/cpu6
-        /sys/devices/system/cpu/cpu7
-        /sys/devices/system/cpu/cpu8
-        /sys/devices/system/cpu/cpu9
-        /sys/devices/system/cpu/cpu10
-        /sys/devices/system/cpu/cpu11
-        /sys/devices/system/cpu/cpu12
-        /sys/devices/system/cpu/cpu13
-        /sys/devices/system/cpu/cpu14
-        /sys/devices/system/cpu/cpu15
-      })
-
-      Facter.fact(:processorcount).value.should == "16"
-    end
   end
 
   describe "on solaris" do

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list