[Pkg-puppet-devel] [facter] 40/180: (maint) Don't cache suitability information
Stig Sandbeck Mathisen
ssm at debian.org
Mon Jun 30 15:06:29 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 1584dc15c4799fe01eacfac249145c6853c95af7
Author: Adrien Thebo <git at somethingsinistral.net>
Date: Mon Mar 31 10:39:33 2014 -0700
(maint) Don't cache suitability information
When testing a resolution, the confines may be tested to confirm
suitability on a given platform and so may be changed without destroying
and recreating the resolution. Because of this we need to recalculate
suitability every time #suitable? method is invoked. In normal operation
fact suitability is only determined once so this should have no
performance impact.
---
lib/facter/core/suitable.rb | 6 +-----
spec/unit/core/suitable_spec.rb | 10 ++++++++++
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/lib/facter/core/suitable.rb b/lib/facter/core/suitable.rb
index 1b3c04f..0262470 100644
--- a/lib/facter/core/suitable.rb
+++ b/lib/facter/core/suitable.rb
@@ -108,10 +108,6 @@ module Facter::Core::Suitable
#
# @api private
def suitable?
- unless defined? @suitable
- @suitable = ! @confines.detect { |confine| ! confine.true? }
- end
-
- return @suitable
+ @confines.all? { |confine| confine.true? }
end
end
diff --git a/spec/unit/core/suitable_spec.rb b/spec/unit/core/suitable_spec.rb
index 4c0b1fd..8277408 100644
--- a/spec/unit/core/suitable_spec.rb
+++ b/spec/unit/core/suitable_spec.rb
@@ -92,5 +92,15 @@ describe Facter::Core::Suitable do
expect(subject).to_not be_suitable
end
+
+ it "recalculates suitability on every invocation" do
+ subject.confine :kernel => 'Linux'
+
+ subject.confines.first.stubs(:true?).returns false
+ expect(subject).to_not be_suitable
+ subject.confines.first.unstub(:true?)
+ subject.confines.first.stubs(:true?).returns true
+ expect(subject).to be_suitable
+ end
end
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