summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-11 11:19:33 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-12 16:12:08 -0700
commit36021021b4cb11aea0a5acd35d051db52d8fc99f (patch)
treeef7b2a6664f1c1a0855b5f131b36d1e68e267e50
parent14b1e008c1368e6c56d68f83999472351fd3327a (diff)
downloadpuppet-36021021b4cb11aea0a5acd35d051db52d8fc99f.tar.gz
puppet-36021021b4cb11aea0a5acd35d051db52d8fc99f.tar.xz
puppet-36021021b4cb11aea0a5acd35d051db52d8fc99f.zip
(#6770) Don't pollute valid face list when #face? is called.
We had two conflicting uses of the list of available faces: in the #face? method we were perfectly happy to create a top level key on any request, but didn't populate the version set. Meanwhile, in #faces we treated the set of top level keys as the absolute and correct list of all *valid* faces, leading to pain and suffering when people queried for an invalid face, but then expected to enumerate only valid faces. Paired-With: Matt Robinson <matt@puppetlabs.com>
-rw-r--r--lib/puppet/interface/face_collection.rb12
-rwxr-xr-xspec/unit/interface/face_collection_spec.rb5
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/puppet/interface/face_collection.rb b/lib/puppet/interface/face_collection.rb
index 84296582c..e4eb22fa3 100644
--- a/lib/puppet/interface/face_collection.rb
+++ b/lib/puppet/interface/face_collection.rb
@@ -53,7 +53,11 @@ module Puppet::Interface::FaceCollection
def self.face?(name, version)
name = underscorize(name)
- return true if @faces[name].has_key?(version)
+
+ # Note: be careful not to accidentally create the top level key, either,
+ # because it will result in confusion when people try to enumerate the
+ # list of valid faces later. --daniel 2011-04-11
+ return true if @faces.has_key?(name) and @faces[name].has_key?(version)
# We always load the current version file; the common case is that we have
# the expected version and any compatibility versions in the same file,
@@ -106,7 +110,11 @@ module Puppet::Interface::FaceCollection
# but we don't need that right now.
#
# So, this comment is a place-holder for that. --daniel 2011-04-06
- return !! @faces[name].has_key?(version)
+ #
+ # Note: be careful not to accidentally create the top level key, either,
+ # because it will result in confusion when people try to enumerate the
+ # list of valid faces later. --daniel 2011-04-11
+ return !! (@faces.has_key?(name) and @faces[name].has_key?(version))
end
def self.register(face)
diff --git a/spec/unit/interface/face_collection_spec.rb b/spec/unit/interface/face_collection_spec.rb
index e6e03c3d2..752871035 100755
--- a/spec/unit/interface/face_collection_spec.rb
+++ b/spec/unit/interface/face_collection_spec.rb
@@ -138,6 +138,11 @@ describe Puppet::Interface::FaceCollection do
subject.face?(:huzzah, :current).should be_true
end
end
+
+ it "should not cause an invalid face to be enumerated later" do
+ subject.face?(:there_is_no_face, :current).should be_false
+ subject.faces.should_not include :there_is_no_face
+ end
end
describe "::register" do