diff options
Diffstat (limited to 'spec/unit/util')
-rwxr-xr-x | spec/unit/util/collection_spec.rb (renamed from spec/unit/util/collection.rb) | 2 | ||||
-rwxr-xr-x | spec/unit/util/confine_spec.rb (renamed from spec/unit/util/confine.rb) | 2 | ||||
-rwxr-xr-x | spec/unit/util/fact_spec.rb (renamed from spec/unit/util/fact.rb) | 2 | ||||
-rwxr-xr-x | spec/unit/util/ip_spec.rb (renamed from spec/unit/util/ip.rb) | 2 | ||||
-rwxr-xr-x | spec/unit/util/loader_spec.rb (renamed from spec/unit/util/loader.rb) | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/unit/util/macaddress_spec.rb (renamed from spec/unit/util/macaddress.rb) | 12 | ||||
-rwxr-xr-x | spec/unit/util/macosx_spec.rb (renamed from spec/unit/util/macosx.rb) | 2 | ||||
-rw-r--r-- | spec/unit/util/manufacturer_spec.rb (renamed from spec/unit/util/manufacturer.rb) | 2 | ||||
-rwxr-xr-x | spec/unit/util/resolution_spec.rb (renamed from spec/unit/util/resolution.rb) | 2 | ||||
-rw-r--r-- | spec/unit/util/uptime.rb | 53 | ||||
-rwxr-xr-x | spec/unit/util/uptime_spec.rb | 73 | ||||
-rw-r--r-- | spec/unit/util/virtual_spec.rb (renamed from spec/unit/util/virtual.rb) | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/unit/util/vlans_spec.rb (renamed from spec/unit/util/vlans.rb) | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/unit/util/xendomains_spec.rb (renamed from spec/unit/util/xendomains.rb) | 4 |
14 files changed, 92 insertions, 72 deletions
diff --git a/spec/unit/util/collection.rb b/spec/unit/util/collection_spec.rb index 7baef96..86b602f 100755 --- a/spec/unit/util/collection.rb +++ b/spec/unit/util/collection_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/collection' diff --git a/spec/unit/util/confine.rb b/spec/unit/util/confine_spec.rb index 757ca26..147c70d 100755 --- a/spec/unit/util/confine.rb +++ b/spec/unit/util/confine_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/confine' require 'facter/util/values' diff --git a/spec/unit/util/fact.rb b/spec/unit/util/fact_spec.rb index 1652032..db08670 100755 --- a/spec/unit/util/fact.rb +++ b/spec/unit/util/fact_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/fact' diff --git a/spec/unit/util/ip.rb b/spec/unit/util/ip_spec.rb index a9aae76..d87b4b9 100755 --- a/spec/unit/util/ip.rb +++ b/spec/unit/util/ip_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/ip' diff --git a/spec/unit/util/loader.rb b/spec/unit/util/loader_spec.rb index 0a28020..0bb823e 100755 --- a/spec/unit/util/loader.rb +++ b/spec/unit/util/loader_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/loader' diff --git a/spec/unit/util/macaddress.rb b/spec/unit/util/macaddress_spec.rb index 1ccca18..98215c4 100644..100755 --- a/spec/unit/util/macaddress.rb +++ b/spec/unit/util/macaddress_spec.rb @@ -1,10 +1,10 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/macaddress' -context "Darwin" do +describe "Darwin" do test_cases = [ # version, iface, real macaddress, fallback macaddress ["9.8.0", 'en0', "00:17:f2:06:e4:2e", "00:17:f2:06:e4:2e"], @@ -17,12 +17,12 @@ context "Darwin" do ifconfig_file_no_iface = File.join(SPECDIR, "fixtures", "ifconfig", "darwin_#{version.tr('.', '_')}") ifconfig_file = "#{ifconfig_file_no_iface}_#{default_iface}" - context "version #{version}" do + describe "version #{version}" do describe Facter::Util::Macaddress::Darwin do describe ".default_interface" do - context "when netstat has a default interface" do + describe "when netstat has a default interface" do before do Facter::Util::Macaddress::Darwin.stubs(:netstat_command).returns("cat \"#{netstat_file}\"") @@ -36,7 +36,7 @@ context "Darwin" do end describe ".macaddress" do - context "when netstat has a default interface" do + describe "when netstat has a default interface" do before do Facter.stubs(:warn) Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns('') @@ -49,7 +49,7 @@ context "Darwin" do end - context "when netstat does not have a default interface" do + describe "when netstat does not have a default interface" do before do Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns("") Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat \"#{ifconfig_file_no_iface}\"") diff --git a/spec/unit/util/macosx.rb b/spec/unit/util/macosx_spec.rb index 283fe75..44ba460 100755 --- a/spec/unit/util/macosx.rb +++ b/spec/unit/util/macosx_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/macosx' diff --git a/spec/unit/util/manufacturer.rb b/spec/unit/util/manufacturer_spec.rb index 291a6ff..07473db 100644 --- a/spec/unit/util/manufacturer.rb +++ b/spec/unit/util/manufacturer_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/manufacturer' diff --git a/spec/unit/util/resolution.rb b/spec/unit/util/resolution_spec.rb index 396f800..581d0e1 100755 --- a/spec/unit/util/resolution.rb +++ b/spec/unit/util/resolution_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/resolution' diff --git a/spec/unit/util/uptime.rb b/spec/unit/util/uptime.rb deleted file mode 100644 index 72c97ed..0000000 --- a/spec/unit/util/uptime.rb +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../spec_helper' - -require 'facter/util/uptime' - -describe Facter::Util::Uptime do - - describe ".get_uptime_seconds_unix" do - context "when /proc/uptime is available" do - before do - uptime_file = File.join(SPECDIR, "fixtures", "uptime", "ubuntu_proc_uptime") - Facter::Util::Uptime.stubs(:uptime_file).returns("\"#{uptime_file}\"") - end - - it "should return the uptime in seconds as an integer" do - Facter::Util::Uptime.get_uptime_seconds_unix.should == 5097686 - end - - end - - it "should use sysctl kern.boottime when /proc/uptime not available" do - nonexistent_file = '/non/existent/file' - File.exists?(nonexistent_file).should == false - Facter::Util::Uptime.stubs(:uptime_file).returns(nonexistent_file) - sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'sysctl_kern_boottime') # Aug 01 14:13:47 -0700 2010 - Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{sysctl_output_file}\"") - Time.stubs(:now).returns Time.parse("Aug 01 15:13:47 -0700 2010") # one hour later - Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 - end - - it "should use who -b when neither /proc/uptime nor sysctl kern.boottime is available" do - nonexistent_file = '/non/existent/file' - File.exists?(nonexistent_file).should == false - Facter::Util::Uptime.stubs(:uptime_file).returns(nonexistent_file) - Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat #{nonexistent_file}") - who_b_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'who_b_boottime') # Aug 1 14:13 - Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{who_b_output_file}\"") - Time.stubs(:now).returns Time.parse("Aug 01 15:13") # one hour later - Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 - end - - it "should return nil when none of /proc/uptime, sysctl kern.boottime, or who -b is available" do - nonexistent_file = '/non/existent/file' - File.exists?(nonexistent_file).should == false - Facter::Util::Uptime.stubs(:uptime_file).returns(nonexistent_file) - Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat #{nonexistent_file}") - Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat #{nonexistent_file}") - Facter::Util::Uptime.get_uptime_seconds_unix.should == nil - end - end - -end diff --git a/spec/unit/util/uptime_spec.rb b/spec/unit/util/uptime_spec.rb new file mode 100755 index 0000000..8d3980c --- /dev/null +++ b/spec/unit/util/uptime_spec.rb @@ -0,0 +1,73 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +require 'facter/util/uptime' + +describe Facter::Util::Uptime do + + describe ".get_uptime_seconds_unix" do + describe "when /proc/uptime is available" do + before do + uptime_file = File.join(SPECDIR, "fixtures", "uptime", "ubuntu_proc_uptime") + Facter::Util::Uptime.stubs(:uptime_file).returns("\"#{uptime_file}\"") + end + + it "should return the uptime in seconds as an integer" do + Facter::Util::Uptime.get_uptime_seconds_unix.should == 5097686 + end + + end + + describe "when /proc/uptime is not available" do + before :each do + @nonexistent_file = '/non/existent/file' + File.exists?(@nonexistent_file).should == false + Facter::Util::Uptime.stubs(:uptime_file).returns(@nonexistent_file) + end + + it "should use 'sysctl kern.boottime'" do + sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'sysctl_kern_boottime') # Aug 01 14:13:47 -0700 2010 + Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{sysctl_output_file}\"") + Time.stubs(:now).returns Time.parse("Aug 01 15:13:47 -0700 2010") # one hour later + Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 + end + + describe "nor is 'sysctl kern.boottime'" do + before :each do + Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{@nonexistent_file}\"") + end + + it "should use 'kstat -p unix:::boot_time'" do + kstat_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'kstat_boot_time') # unix:0:system_misc:boot_time 1236919980 + Facter::Util::Uptime.stubs(:uptime_kstat_cmd).returns("cat \"#{kstat_output_file}\"") + Time.stubs(:now).returns Time.at(1236923580) #one hour later + Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 + end + + describe "nor is 'kstat -p unix:::boot_time'" do + before :each do + Facter::Util::Uptime.stubs(:uptime_kstat_cmd).returns("cat \"#{@nonexistent_file}\"") + end + + it "should use 'who -b'" do + who_b_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'who_b_boottime') # Aug 1 14:13 + Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{who_b_output_file}\"") + Time.stubs(:now).returns Time.parse("Aug 01 15:13") # one hour later + Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 + end + + describe "nor is 'who -b'" do + before :each do + Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{@nonexistent_file}\"") + end + + it "should return nil" do + Facter::Util::Uptime.get_uptime_seconds_unix.should == nil + end + end + end + end + end + end +end diff --git a/spec/unit/util/virtual.rb b/spec/unit/util/virtual_spec.rb index 72186f7..12ba0ac 100644 --- a/spec/unit/util/virtual.rb +++ b/spec/unit/util/virtual_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/virtual' @@ -67,7 +67,7 @@ describe Facter::Util::Virtual do ] test_cases.each do |status_file, expected, description| - context "with /proc/self/status from #{description}" do + describe "with /proc/self/status from #{description}" do it "should detect vserver as #{expected.inspect}" do status = File.read(status_file) FileTest.stubs(:exists?).with("/proc/self/status").returns(true) diff --git a/spec/unit/util/vlans.rb b/spec/unit/util/vlans_spec.rb index e06a2af..0331234 100644..100755 --- a/spec/unit/util/vlans.rb +++ b/spec/unit/util/vlans_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/vlans' diff --git a/spec/unit/util/xendomains.rb b/spec/unit/util/xendomains_spec.rb index a0fa345..dc7e178 100644..100755 --- a/spec/unit/util/xendomains.rb +++ b/spec/unit/util/xendomains_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/xendomains' @@ -13,7 +13,7 @@ describe Facter::Util::Xendomains do Facter::Util::Xendomains.get_domains.should == %{web01,mailserver} end - context "when xm list isn't executable" do + describe "when xm list isn't executable" do it "should be nil" do Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/xm list').returns(nil) Facter::Util::Xendomains.get_domains.should == nil |