diff options
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | lib/puppet/provider/confine/variable.rb | 13 | ||||
-rwxr-xr-x | spec/unit/provider/confine/variable.rb | 32 |
3 files changed, 27 insertions, 20 deletions
@@ -1,4 +1,6 @@ 0.24.x + Fixed #1735 and #1747 - Fixes to confine system + Fixed #1681 - Add filesystem type check to test for per-file SELinux context support Fixed #1746 - Sync SELinux file attributes after file contents created/modified diff --git a/lib/puppet/provider/confine/variable.rb b/lib/puppet/provider/confine/variable.rb index c868a4e9e..9bef69412 100644 --- a/lib/puppet/provider/confine/variable.rb +++ b/lib/puppet/provider/confine/variable.rb @@ -24,6 +24,11 @@ class Puppet::Provider::Confine::Variable < Puppet::Provider::Confine @facter_value end + def initialize(values) + super + @values = @values.collect { |v| v.to_s.downcase } + end + def message(value) "facter value '%s' for '%s' not in required list '%s'" % [test_value, self.name, values.join(",")] end @@ -35,10 +40,16 @@ class Puppet::Provider::Confine::Variable < Puppet::Provider::Confine def reset # Reset the cache. We want to cache it during a given - # run, but across runs. + # run, but not across runs. @facter_value = nil end + def valid? + @values.include?(test_value.to_s.downcase) + ensure + reset + end + private def setting? diff --git a/spec/unit/provider/confine/variable.rb b/spec/unit/provider/confine/variable.rb index 38b3dad1c..5f4c6c7a2 100755 --- a/spec/unit/provider/confine/variable.rb +++ b/spec/unit/provider/confine/variable.rb @@ -27,52 +27,40 @@ describe Puppet::Provider::Confine::Variable do @confine.name = :myvar end - it "should use the 'pass?' method to test validity" do - @confine.expects(:pass?).with("foo") - @confine.valid? - end - it "should use settings if the variable name is a valid setting" do Puppet.settings.expects(:valid?).with(:myvar).returns true Puppet.settings.expects(:value).with(:myvar).returns "foo" - @confine.pass?("foo") + @confine.valid? end it "should use Facter if the variable name is not a valid setting" do Puppet.settings.expects(:valid?).with(:myvar).returns false Facter.expects(:value).with(:myvar).returns "foo" - @confine.pass?("foo") + @confine.valid? end - it "should return true if the value matches the facter value" do + it "should be valid if the value matches the facter value" do @confine.expects(:test_value).returns "foo" - @confine.pass?("foo").should be_true + @confine.should be_valid end it "should return false if the value does not match the facter value" do @confine.expects(:test_value).returns "fee" - @confine.pass?("foo").should be_false + @confine.should_not be_valid end it "should be case insensitive" do @confine.expects(:test_value).returns "FOO" - @confine.pass?("foo").should be_true + @confine.should be_valid end it "should not care whether the value is a string or symbol" do @confine.expects(:test_value).returns "FOO" - @confine.pass?(:foo).should be_true - end - - it "should cache the facter value during testing" do - Facter.expects(:value).once.returns("FOO") - - @confine.pass?(:foo) - @confine.pass?(:foo) + @confine.should be_valid end it "should produce a message that the fact value is not correct" do @@ -81,6 +69,12 @@ describe Puppet::Provider::Confine::Variable do message.should be_include("facter") message.should be_include("bar,bee") end + + it "should be valid if the test value matches any of the provided values" do + @confine = Puppet::Provider::Confine::Variable.new(%w{bar bee}) + @confine.expects(:test_value).returns "bee" + @confine.should be_valid + end end describe "when summarizing multiple instances" do |