[Pkg-puppet-devel] [facter] 28/61: Maint: Don't load facts twice during specs
Stig Sandbeck Mathisen
ssm at debian.org
Mon Nov 4 15:01:54 UTC 2013
This is an automated email from the git hooks/post-receive script.
ssm pushed a commit to branch master
in repository facter.
commit 995232eeb54b0aede5df5dea6ad4a35aee5c8208
Author: Josh Cooper <josh at puppetlabs.com>
Date: Mon Jul 29 14:26:46 2013 -0700
Maint: Don't load facts twice during specs
Previously, the spec_helper was prepending facter's lib directory to the
$LOAD_PATH, which had the side-effect of causing the zfs and zpool commands
to be executed 5 times, not 3 (as specified in the comments).
Originally, this was noticed because we were having to add `.at_least_once`
to expectations even though the method should have only been called once.
This commit changes the spec_helper to no longer prepend facter's top-level
lib directory to the LOAD_PATH. In doing so, it causes the virtual fact
resolutions to be evaluated in a different order than the virtual tests
expected. In particular, the tests we're trying to verify the more-specific
resolution, but were actually running with the more generic one.
This commit adds a higher weight to the more specific virtual facts,
since that's the expected behavior, and it ensures the tests reliably
test the resolution they are trying to set their expectations on.
Paired-with: Patrick Carlisle <patrick at puppetlabs.com>
---
lib/facter/virtual.rb | 10 +++++-----
spec/spec_helper.rb | 10 +++-------
spec/unit/ec2_spec.rb | 2 +-
spec/unit/zfs_version_spec.rb | 9 ++++-----
spec/unit/zpool_version_spec.rb | 9 ++++-----
5 files changed, 17 insertions(+), 23 deletions(-)
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index 72ef9fb..c65a4bd 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -46,7 +46,7 @@ end
Facter.add("virtual") do
confine :kernel => ["FreeBSD", "GNU/kFreeBSD"]
-
+ has_weight 10
setcode do
"jail" if Facter::Util::Virtual.jail?
end
@@ -54,7 +54,7 @@ end
Facter.add("virtual") do
confine :kernel => 'SunOS'
-
+ has_weight 10
setcode do
next "zone" if Facter::Util::Virtual.zone?
@@ -74,7 +74,7 @@ end
Facter.add("virtual") do
confine :kernel => 'HP-UX'
-
+ has_weight 10
setcode do
"hpvm" if Facter::Util::Virtual.hpvm?
end
@@ -82,7 +82,7 @@ end
Facter.add("virtual") do
confine :architecture => 's390x'
-
+ has_weight 10
setcode do
"zlinux" if Facter::Util::Virtual.zlinux?
end
@@ -90,7 +90,7 @@ end
Facter.add("virtual") do
confine :kernel => 'OpenBSD'
-
+ has_weight 10
setcode do
output = Facter::Util::Resolution.exec('sysctl -n hw.product 2>/dev/null')
if output
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index b0d8566..ead2438 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,10 +1,3 @@
-# Add the projects lib directory to our load path so we can require libraries
-# within it easily.
-dir = File.expand_path(File.dirname(__FILE__))
-
-SPECDIR = dir
-$LOAD_PATH.unshift("#{dir}/../lib")
-
require 'rubygems'
require 'mocha'
require 'rspec'
@@ -13,6 +6,9 @@ require 'fileutils'
require 'puppetlabs_spec_helper'
require 'pathname'
+# load shared_context within this project's spec directory
+dir = File.expand_path(File.dirname(__FILE__))
+
Pathname.glob("#{dir}/shared_contexts/*.rb") do |file|
require file.relative_path_from(Pathname.new(dir))
end
diff --git a/spec/unit/ec2_spec.rb b/spec/unit/ec2_spec.rb
index 93d0939..3046789 100755
--- a/spec/unit/ec2_spec.rb
+++ b/spec/unit/ec2_spec.rb
@@ -136,7 +136,7 @@ describe "ec2 facts" do
end
it "should return nil if open fails" do
- Facter.expects(:warn).with('Could not retrieve ec2 metadata: host unreachable').twice
+ Facter.expects(:warn).with('Could not retrieve ec2 metadata: host unreachable')
Facter::Util::Resolution.any_instance.stubs(:warn) # do not pollute test output
Object.any_instance.expects(:open).
diff --git a/spec/unit/zfs_version_spec.rb b/spec/unit/zfs_version_spec.rb
index 905dbc9..2bfc01e 100644
--- a/spec/unit/zfs_version_spec.rb
+++ b/spec/unit/zfs_version_spec.rb
@@ -56,11 +56,10 @@ describe "zfs_version fact" do
it "handles the zfs command becoming available at a later point in time" do
# Simulate Puppet configuring the zfs tools from a persistent daemon by
- # simulating three sequential responses to which('zfs')
- # (NOTE, each resolution causes which to execute twice.
+ # simulating three sequential responses to which('zfs').
Facter::Util::Resolution.stubs(:which).
with("zfs").
- returns(nil,nil,nil,nil,"/usr/bin/zfs")
+ returns(nil,nil,"/usr/bin/zfs")
Facter::Util::Resolution.stubs(:exec).
with("zfs upgrade -v").
returns(my_fixture_read('linux-fuse_0.6.9'))
@@ -68,8 +67,8 @@ describe "zfs_version fact" do
fact = Facter.fact(:zfs_version)
# zfs is not present the first two times the fact is resolved.
- fact.value.should_not == "4"
- fact.value.should_not == "4"
+ fact.value.should be_nil
+ fact.value.should be_nil
# zfs was configured between the second and third resolutions.
fact.value.should == "4"
end
diff --git a/spec/unit/zpool_version_spec.rb b/spec/unit/zpool_version_spec.rb
index 0cba70f..fc6a952 100644
--- a/spec/unit/zpool_version_spec.rb
+++ b/spec/unit/zpool_version_spec.rb
@@ -56,11 +56,10 @@ describe "zpool_version fact" do
it "handles the zpool command becoming available" do
# Simulate Puppet configuring the zfs tools from a persistent daemon by
- # simulating three sequential responses to which('zpool')
- # (NOTE, each resolution causes which to execute twice.
+ # simulating three sequential responses to which('zpool').
Facter::Util::Resolution.stubs(:which).
with("zpool").
- returns(nil,nil,nil,nil,"/usr/bin/zpool")
+ returns(nil,nil,"/usr/bin/zpool")
Facter::Util::Resolution.stubs(:exec).
with("zpool upgrade -v").
returns(my_fixture_read('linux-fuse_0.6.9'))
@@ -68,8 +67,8 @@ describe "zpool_version fact" do
fact = Facter.fact(:zpool_version)
# zfs is not present the first two times the fact is resolved.
- fact.value.should_not == "23"
- fact.value.should_not == "23"
+ fact.value.should be_nil
+ fact.value.should be_nil
# zfs was configured between the second and third resolutions.
fact.value.should == "23"
end
--
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