facter 1.6.4 → 1.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +33 -1
- data/conf/redhat/facter.spec +2 -1
- data/install.rb +25 -23
- data/lib/facter.rb +2 -1
- data/lib/facter/domain.rb +4 -4
- data/lib/facter/ec2.rb +6 -28
- data/lib/facter/hardwareisa.rb +0 -1
- data/lib/facter/hardwaremodel.rb +1 -1
- data/lib/facter/lsbmajdistrelease.rb +1 -1
- data/lib/facter/macaddress.rb +1 -1
- data/lib/facter/memory.rb +15 -4
- data/lib/facter/operatingsystem.rb +8 -4
- data/lib/facter/osfamily.rb +1 -1
- data/lib/facter/uniqueid.rb +1 -1
- data/lib/facter/util/collection.rb +2 -3
- data/lib/facter/util/config.rb +3 -3
- data/lib/facter/util/ec2.rb +49 -0
- data/lib/facter/util/fact.rb +12 -7
- data/lib/facter/util/monkey_patches.rb +7 -0
- data/lib/facter/util/uptime.rb +2 -2
- data/lib/facter/util/virtual.rb +1 -1
- data/lib/facter/virtual.rb +11 -1
- data/spec/{unit/data → fixtures/unit/selinux}/selinux_sestatus +0 -0
- data/spec/fixtures/unit/util/ec2/linux-arp-ec2.out +1 -0
- data/spec/fixtures/unit/util/ec2/linux-arp-not-ec2.out +5 -0
- data/spec/fixtures/unit/util/ec2/windows-2008-arp-a-not-ec2.out +6 -0
- data/spec/fixtures/unit/util/ec2/windows-2008-arp-a.out +10 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/6.0-STABLE_FreeBSD_ifconfig +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/Mac_OS_X_10.5.5_ifconfig +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/darwin_ifconfig_all_with_multiple_interfaces +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/darwin_ifconfig_single_interface +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/debian_kfreebsd_ifconfig +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/hpux_ifconfig_single_interface +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/hpux_netstat_all_interfaces +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/linux_ifconfig_all_with_single_interface +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/solaris_ifconfig_all_with_multiple_interfaces +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/solaris_ifconfig_single_interface +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/windows_netsh_all_interfaces +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/windows_netsh_single_interface +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/windows_netsh_single_interface6 +0 -0
- data/spec/{unit/data → fixtures/unit/util/manufacturer}/freebsd_dmidecode +0 -0
- data/spec/{unit/data → fixtures/unit/util/manufacturer}/linux_dmidecode_with_spaces +0 -0
- data/spec/{unit/data → fixtures/unit/util/manufacturer}/opensolaris_smbios +0 -0
- data/spec/fixtures/{uptime → unit/util/uptime}/kstat_boot_time +0 -0
- data/spec/fixtures/unit/util/uptime/sysctl_kern_boottime_darwin +1 -0
- data/spec/fixtures/unit/util/uptime/sysctl_kern_boottime_openbsd +1 -0
- data/spec/fixtures/{uptime → unit/util/uptime}/ubuntu_proc_uptime +0 -0
- data/spec/fixtures/{uptime → unit/util/uptime}/who_b_boottime +0 -0
- data/spec/{unit/data → fixtures/unit/util/vlans}/linux_vlan_config +0 -0
- data/spec/{unit/data → fixtures/unit/util/xendomains}/xendomains +0 -0
- data/spec/integration/facter_spec.rb +2 -2
- data/spec/puppetlabs_spec/files.rb +57 -0
- data/spec/puppetlabs_spec/fixtures.rb +49 -0
- data/spec/puppetlabs_spec/matchers.rb +87 -0
- data/spec/puppetlabs_spec_helper.rb +25 -0
- data/spec/spec_helper.rb +9 -12
- data/spec/unit/architecture_spec.rb +2 -4
- data/spec/unit/domain_spec.rb +3 -1
- data/spec/unit/ec2_spec.rb +140 -0
- data/spec/unit/facter_spec.rb +2 -2
- data/spec/unit/hardwareisa_spec.rb +34 -0
- data/spec/unit/hostname_spec.rb +3 -1
- data/spec/unit/id_spec.rb +2 -2
- data/spec/unit/interfaces_spec.rb +2 -4
- data/spec/unit/ipaddress6_spec.rb +4 -7
- data/spec/unit/lsbmajdistrelease_spec.rb +13 -0
- data/spec/unit/macaddress_spec.rb +4 -7
- data/spec/unit/memory_spec.rb +11 -6
- data/spec/unit/operatingsystem_spec.rb +101 -69
- data/spec/unit/operatingsystemrelease_spec.rb +2 -4
- data/spec/unit/physicalprocessorcount_spec.rb +1 -1
- data/spec/unit/processor_spec.rb +32 -35
- data/spec/unit/selinux_spec.rb +5 -10
- data/spec/unit/uniqueid_spec.rb +27 -0
- data/spec/unit/uptime_spec.rb +2 -4
- data/spec/unit/util/collection_spec.rb +12 -3
- data/spec/unit/util/config_spec.rb +24 -0
- data/spec/unit/util/confine_spec.rb +2 -3
- data/spec/unit/util/ec2_spec.rb +112 -0
- data/spec/unit/util/fact_spec.rb +2 -3
- data/spec/unit/util/ip_spec.rb +27 -55
- data/spec/unit/util/loader_spec.rb +2 -4
- data/spec/unit/util/macaddress_spec.rb +4 -5
- data/spec/unit/util/macosx_spec.rb +2 -3
- data/spec/unit/util/manufacturer_spec.rb +8 -9
- data/spec/unit/util/processor_spec.rb +8 -10
- data/spec/unit/util/resolution_spec.rb +2 -3
- data/spec/unit/util/uptime_spec.rb +15 -14
- data/spec/unit/util/virtual_spec.rb +10 -2
- data/spec/unit/util/vlans_spec.rb +3 -5
- data/spec/unit/util/wmi_spec.rb +2 -3
- data/spec/unit/util/xendomains_spec.rb +3 -5
- data/spec/unit/virtual_spec.rb +48 -18
- metadata +44 -28
- data/spec/fixtures/uptime/sysctl_kern_boottime_big_endian +0 -0
- data/spec/fixtures/uptime/sysctl_kern_boottime_little_endian +0 -0
data/lib/facter/util/fact.rb
CHANGED
|
@@ -33,17 +33,22 @@ class Facter::Util::Fact
|
|
|
33
33
|
def add(&block)
|
|
34
34
|
raise ArgumentError, "You must pass a block to Fact<instance>.add" unless block_given?
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
begin
|
|
37
|
+
resolve = Facter::Util::Resolution.new(@name)
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
resolve.instance_eval(&block)
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
@resolves << resolve
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
# Immediately sort the resolutions, so that we always have
|
|
44
|
+
# a sorted list for looking up values.
|
|
45
|
+
@resolves.sort! { |a, b| b.weight <=> a.weight }
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
resolve
|
|
48
|
+
rescue => e
|
|
49
|
+
Facter.warn "Unable to add resolve for #{@name}: #{e}"
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
47
52
|
end
|
|
48
53
|
|
|
49
54
|
# Flush any cached values.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# This provides an alias for RbConfig to Config for versions of Ruby older then
|
|
2
|
+
# version 1.8.5. This allows us to use RbConfig in place of the older Config in
|
|
3
|
+
# our code and still be compatible with at least Ruby 1.8.1.
|
|
4
|
+
require 'rbconfig'
|
|
5
|
+
unless defined? ::RbConfig
|
|
6
|
+
::RbConfig = ::Config
|
|
7
|
+
end
|
data/lib/facter/util/uptime.rb
CHANGED
|
@@ -27,7 +27,7 @@ module Facter::Util::Uptime
|
|
|
27
27
|
|
|
28
28
|
def self.uptime_sysctl
|
|
29
29
|
if output = Facter::Util::Resolution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
|
|
30
|
-
compute_uptime(Time.at(output.
|
|
30
|
+
compute_uptime(Time.at(output.match(/\d+/)[0].to_i))
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -52,7 +52,7 @@ module Facter::Util::Uptime
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def self.uptime_sysctl_cmd
|
|
55
|
-
'sysctl -
|
|
55
|
+
'sysctl -n kern.boottime'
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
def self.uptime_kstat_cmd
|
data/lib/facter/util/virtual.rb
CHANGED
|
@@ -55,7 +55,7 @@ module Facter::Util::Virtual
|
|
|
55
55
|
def self.kvm?
|
|
56
56
|
txt = if FileTest.exists?("/proc/cpuinfo")
|
|
57
57
|
File.read("/proc/cpuinfo")
|
|
58
|
-
elsif Facter.value(:kernel)
|
|
58
|
+
elsif ["FreeBSD", "OpenBSD"].include? Facter.value(:kernel)
|
|
59
59
|
Facter::Util::Resolution.exec("/sbin/sysctl -n hw.model")
|
|
60
60
|
end
|
|
61
61
|
(txt =~ /QEMU Virtual CPU/) ? true : false
|
data/lib/facter/virtual.rb
CHANGED
|
@@ -52,7 +52,7 @@ Facter.add("virtual") do
|
|
|
52
52
|
|
|
53
53
|
setcode do
|
|
54
54
|
|
|
55
|
-
if Facter.value(:
|
|
55
|
+
if Facter.value(:kernel) == "SunOS" and Facter::Util::Virtual.zone?
|
|
56
56
|
result = "zone"
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -131,6 +131,16 @@ Facter.add("virtual") do
|
|
|
131
131
|
result = "xenhvm" if pd =~ /HVM domU/
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
|
+
elsif Facter.value(:kernel) == 'OpenBSD'
|
|
135
|
+
output = Facter::Util::Resolution.exec('sysctl -n hw.product 2>/dev/null')
|
|
136
|
+
if not output.nil?
|
|
137
|
+
output.each_line do |pd|
|
|
138
|
+
result = "parallels" if pd =~ /Parallels/
|
|
139
|
+
result = "vmware" if pd =~ /VMware/
|
|
140
|
+
result = "virtualbox" if pd =~ /VirtualBox/
|
|
141
|
+
result = "xenhvm" if pd =~ /HVM domU/
|
|
142
|
+
end
|
|
143
|
+
end
|
|
134
144
|
end
|
|
135
145
|
end
|
|
136
146
|
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
? (10.240.93.1) at fe:ff:ff:ff:ff:ff [ether] on eth0
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
? (46.4.106.97) at 00:26:88:75:c1:17 [ether] on eth0
|
|
2
|
+
? (10.1.2.14) at 02:00:0a:01:02:0e [ether] on virbr1
|
|
3
|
+
? (10.1.2.12) at 02:00:0a:01:02:0c [ether] on virbr1
|
|
4
|
+
? (10.1.2.11) at 02:00:0a:01:02:0b [ether] on virbr1
|
|
5
|
+
? (10.1.2.200) at 02:00:0a:01:02:0e [ether] on virbr1
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
Interface: 10.32.123.54 --- 0xd
|
|
3
|
+
Internet Address Physical Address Type
|
|
4
|
+
10.32.120.163 fe-ff-ff-ff-ff-ff dynamic
|
|
5
|
+
10.32.122.1 fe-ff-ff-ff-ff-ff dynamic
|
|
6
|
+
10.32.123.255 ff-ff-ff-ff-ff-ff static
|
|
7
|
+
169.254.169.254 fe-ff-ff-ff-ff-ff dynamic
|
|
8
|
+
224.0.0.22 01-00-5e-00-00-16 static
|
|
9
|
+
224.0.0.252 01-00-5e-00-00-fc static
|
|
10
|
+
255.255.255.255 ff-ff-ff-ff-ff-ff static
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ sec = 1320011547, usec = 0 } Sun Oct 30 21:52:27 2011
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1323465106
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
require 'tempfile'
|
|
3
|
+
require 'pathname'
|
|
4
|
+
|
|
5
|
+
# A support module for testing files.
|
|
6
|
+
module PuppetlabsSpec::Files
|
|
7
|
+
# This code exists only to support tests that run as root, pretty much.
|
|
8
|
+
# Once they have finally been eliminated this can all go... --daniel 2011-04-08
|
|
9
|
+
def self.in_tmp(path)
|
|
10
|
+
tempdir = Dir.tmpdir
|
|
11
|
+
|
|
12
|
+
Pathname.new(path).ascend do |dir|
|
|
13
|
+
return true if File.identical?(tempdir, dir)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.cleanup
|
|
20
|
+
$global_tempfiles ||= []
|
|
21
|
+
while path = $global_tempfiles.pop do
|
|
22
|
+
fail "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path)
|
|
23
|
+
|
|
24
|
+
begin
|
|
25
|
+
FileUtils.rm_r path, :secure => true
|
|
26
|
+
rescue Errno::ENOENT
|
|
27
|
+
# nothing to do
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def make_absolute(path)
|
|
33
|
+
path = File.expand_path(path)
|
|
34
|
+
path[0] = 'c' if Puppet.features.microsoft_windows?
|
|
35
|
+
path
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def tmpfilename(name)
|
|
39
|
+
# Generate a temporary file, just for the name...
|
|
40
|
+
source = Tempfile.new(name)
|
|
41
|
+
path = source.path
|
|
42
|
+
source.close!
|
|
43
|
+
|
|
44
|
+
# ...record it for cleanup,
|
|
45
|
+
$global_tempfiles ||= []
|
|
46
|
+
$global_tempfiles << File.expand_path(path)
|
|
47
|
+
|
|
48
|
+
# ...and bam.
|
|
49
|
+
path
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def tmpdir(name)
|
|
53
|
+
path = tmpfilename(name)
|
|
54
|
+
FileUtils.mkdir_p(path)
|
|
55
|
+
path
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# This module provides some helper methods to assist with fixtures. It's
|
|
2
|
+
# methods are designed to help when you have a conforming fixture layout so we
|
|
3
|
+
# get project consistency.
|
|
4
|
+
module PuppetlabsSpec::Fixtures
|
|
5
|
+
|
|
6
|
+
# Returns the joined path of the global FIXTURE_DIR plus any path given to it
|
|
7
|
+
def fixtures(*rest)
|
|
8
|
+
File.join(PuppetlabsSpec::FIXTURE_DIR, *rest)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Returns the path to your relative fixture dir. So if your spec test is
|
|
12
|
+
# <project>/spec/unit/facter/foo_spec.rb then your relative dir will be
|
|
13
|
+
# <project>/spec/fixture/unit/facter/foo
|
|
14
|
+
def my_fixture_dir
|
|
15
|
+
callers = caller
|
|
16
|
+
while line = callers.shift do
|
|
17
|
+
next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
|
|
18
|
+
return fixtures(found[1])
|
|
19
|
+
end
|
|
20
|
+
fail "sorry, I couldn't work out your path from the caller stack!"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Given a name, returns the full path of a file from your relative fixture
|
|
24
|
+
# dir as returned by my_fixture_dir.
|
|
25
|
+
def my_fixture(name)
|
|
26
|
+
file = File.join(my_fixture_dir, name)
|
|
27
|
+
unless File.readable? file then
|
|
28
|
+
fail "fixture '#{name}' for #{my_fixture_dir} is not readable"
|
|
29
|
+
end
|
|
30
|
+
return file
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Return the contents of the file using read when given a name. Uses
|
|
34
|
+
# my_fixture to work out the relative path.
|
|
35
|
+
def my_fixture_read(name)
|
|
36
|
+
File.read(my_fixture(name))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Provides a block mechanism for iterating across the files in your fixture
|
|
40
|
+
# area.
|
|
41
|
+
def my_fixtures(glob = '*', flags = 0)
|
|
42
|
+
files = Dir.glob(File.join(my_fixture_dir, glob), flags)
|
|
43
|
+
unless files.length > 0 then
|
|
44
|
+
fail "fixture '#{glob}' for #{my_fixture_dir} had no files!"
|
|
45
|
+
end
|
|
46
|
+
block_given? and files.each do |file| yield file end
|
|
47
|
+
files
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require 'stringio'
|
|
2
|
+
|
|
3
|
+
########################################################################
|
|
4
|
+
# Backward compatibility for Jenkins outdated environment.
|
|
5
|
+
module RSpec
|
|
6
|
+
module Matchers
|
|
7
|
+
module BlockAliases
|
|
8
|
+
alias_method :to, :should unless method_defined? :to
|
|
9
|
+
alias_method :to_not, :should_not unless method_defined? :to_not
|
|
10
|
+
alias_method :not_to, :should_not unless method_defined? :not_to
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
########################################################################
|
|
17
|
+
# Custom matchers...
|
|
18
|
+
RSpec::Matchers.define :have_matching_element do |expected|
|
|
19
|
+
match do |actual|
|
|
20
|
+
actual.any? { |item| item =~ expected }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
RSpec::Matchers.define :exit_with do |expected|
|
|
26
|
+
actual = nil
|
|
27
|
+
match do |block|
|
|
28
|
+
begin
|
|
29
|
+
block.call
|
|
30
|
+
rescue SystemExit => e
|
|
31
|
+
actual = e.status
|
|
32
|
+
end
|
|
33
|
+
actual and actual == expected
|
|
34
|
+
end
|
|
35
|
+
failure_message_for_should do |block|
|
|
36
|
+
"expected exit with code #{expected} but " +
|
|
37
|
+
(actual.nil? ? " exit was not called" : "we exited with #{actual} instead")
|
|
38
|
+
end
|
|
39
|
+
failure_message_for_should_not do |block|
|
|
40
|
+
"expected that exit would not be called with #{expected}"
|
|
41
|
+
end
|
|
42
|
+
description do
|
|
43
|
+
"expect exit with #{expected}"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
RSpec::Matchers.define :have_printed do |expected|
|
|
49
|
+
match do |block|
|
|
50
|
+
$stderr = $stdout = StringIO.new
|
|
51
|
+
|
|
52
|
+
begin
|
|
53
|
+
block.call
|
|
54
|
+
ensure
|
|
55
|
+
$stdout.rewind
|
|
56
|
+
@actual = $stdout.read
|
|
57
|
+
|
|
58
|
+
$stdout = STDOUT
|
|
59
|
+
$stderr = STDERR
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
if @actual then
|
|
63
|
+
case expected
|
|
64
|
+
when String
|
|
65
|
+
@actual.include? expected
|
|
66
|
+
when Regexp
|
|
67
|
+
expected.match @actual
|
|
68
|
+
else
|
|
69
|
+
raise ArgumentError, "No idea how to match a #{@actual.class.name}"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
failure_message_for_should do |actual|
|
|
75
|
+
if actual.nil? then
|
|
76
|
+
"expected #{expected.inspect}, but nothing was printed"
|
|
77
|
+
else
|
|
78
|
+
"expected #{expected.inspect} to be printed; got:\n#{actual}"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
description do
|
|
83
|
+
"expect #{expected.inspect} to be printed"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
diffable
|
|
87
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Define the main module namespace for use by the helper modules
|
|
2
|
+
module PuppetlabsSpec
|
|
3
|
+
# FIXTURE_DIR represents the standard locations of all fixture data. Normally
|
|
4
|
+
# this represents <project>/spec/fixtures. This will be used by the fixtures
|
|
5
|
+
# library to find relative fixture data.
|
|
6
|
+
FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), \
|
|
7
|
+
"fixtures") unless defined?(FIXTURE_DIR)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Require all necessary helper libraries so they can be used later
|
|
11
|
+
require 'puppetlabs_spec/files'
|
|
12
|
+
require 'puppetlabs_spec/fixtures'
|
|
13
|
+
require 'puppetlabs_spec/matchers'
|
|
14
|
+
|
|
15
|
+
RSpec.configure do |config|
|
|
16
|
+
# Include PuppetlabsSpec helpers so they can be called at convenience
|
|
17
|
+
config.extend PuppetlabsSpec::Files
|
|
18
|
+
config.extend PuppetlabsSpec::Fixtures
|
|
19
|
+
config.include PuppetlabsSpec::Fixtures
|
|
20
|
+
|
|
21
|
+
# This will cleanup any files that were created with tmpdir or tmpfile
|
|
22
|
+
config.after :each do
|
|
23
|
+
PuppetlabsSpec::Files.cleanup
|
|
24
|
+
end
|
|
25
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
|
+
# Add the projects lib directory to our load path so we can require libraries
|
|
2
|
+
# within it easily.
|
|
1
3
|
dir = File.expand_path(File.dirname(__FILE__))
|
|
2
4
|
|
|
3
5
|
SPECDIR = dir
|
|
4
|
-
|
|
5
|
-
def fixture_data(file)
|
|
6
|
-
File.read(File.join(SPECDIR, "fixtures", file))
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
$LOAD_PATH.unshift("#{dir}/")
|
|
11
6
|
$LOAD_PATH.unshift("#{dir}/../lib")
|
|
12
7
|
|
|
13
8
|
require 'rubygems'
|
|
14
9
|
require 'mocha'
|
|
15
10
|
require 'rspec'
|
|
16
11
|
require 'facter'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Dir["#{dir}/monkey_patches/*.rb"].map { |file| require file }
|
|
12
|
+
require 'fileutils'
|
|
13
|
+
require 'puppetlabs_spec_helper'
|
|
20
14
|
|
|
21
15
|
RSpec.configure do |config|
|
|
22
16
|
config.mock_with :mocha
|
|
23
17
|
|
|
24
|
-
# Ensure that we don't accidentally cache facts and environment
|
|
25
|
-
# between test cases.
|
|
26
18
|
config.before :each do
|
|
19
|
+
# Ensure that we don't accidentally cache facts and environment
|
|
20
|
+
# between test cases.
|
|
27
21
|
Facter::Util::Loader.any_instance.stubs(:load_all)
|
|
28
22
|
Facter.clear
|
|
29
23
|
Facter.clear_messages
|
|
24
|
+
|
|
25
|
+
# Store any environment variables away to be restored later
|
|
30
26
|
@old_env = {}
|
|
31
27
|
ENV.each_key {|k| @old_env[k] = ENV[k]}
|
|
32
28
|
end
|
|
33
29
|
|
|
34
30
|
config.after :each do
|
|
31
|
+
# Restore environment variables after execution of each test
|
|
35
32
|
@old_env.each_pair {|k, v| ENV[k] = v}
|
|
36
33
|
to_remove = ENV.keys.reject {|key| @old_env.include? key }
|
|
37
34
|
to_remove.each {|key| ENV.delete key }
|