diff options
| -rw-r--r-- | lib/puppet/provider/confine.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/provider/confine/variable.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/provider/confine_collection.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/provider/confiner.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/provider/confine.rb | 13 | ||||
| -rwxr-xr-x | spec/unit/provider/confine_collection.rb | 56 | ||||
| -rwxr-xr-x | spec/unit/provider/confiner.rb | 3 |
7 files changed, 58 insertions, 28 deletions
diff --git a/lib/puppet/provider/confine.rb b/lib/puppet/provider/confine.rb index 70148fc33..ff97831ee 100644 --- a/lib/puppet/provider/confine.rb +++ b/lib/puppet/provider/confine.rb @@ -42,6 +42,9 @@ class Puppet::Provider::Confine for_binary end + # Used for logging. + attr_accessor :label + def initialize(values) values = [values] unless values.is_a?(Array) @values = values @@ -61,7 +64,7 @@ class Puppet::Provider::Confine def valid? values.each do |value| unless pass?(value) - Puppet.debug message(value) + Puppet.debug(label + ": " + message(value)) return false end end diff --git a/lib/puppet/provider/confine/variable.rb b/lib/puppet/provider/confine/variable.rb index 0ef90d6d8..c868a4e9e 100644 --- a/lib/puppet/provider/confine/variable.rb +++ b/lib/puppet/provider/confine/variable.rb @@ -25,7 +25,7 @@ class Puppet::Provider::Confine::Variable < Puppet::Provider::Confine end def message(value) - "facter value '%s' for '%s' not in required list '%s'" % [value, self.name, values.join(",")] + "facter value '%s' for '%s' not in required list '%s'" % [test_value, self.name, values.join(",")] end # Compare the passed-in value to the retrieved value. diff --git a/lib/puppet/provider/confine_collection.rb b/lib/puppet/provider/confine_collection.rb index 35f461acb..0dbdc7790 100644 --- a/lib/puppet/provider/confine_collection.rb +++ b/lib/puppet/provider/confine_collection.rb @@ -19,10 +19,13 @@ class Puppet::Provider::ConfineCollection confine.name = test @confines << confine end + @confines[-1].label = self.label end end - def initialize + attr_reader :label + def initialize(label) + @label = label @confines = [] end diff --git a/lib/puppet/provider/confiner.rb b/lib/puppet/provider/confiner.rb index 4605523e8..65243efce 100644 --- a/lib/puppet/provider/confiner.rb +++ b/lib/puppet/provider/confiner.rb @@ -7,7 +7,7 @@ module Puppet::Provider::Confiner def confine_collection unless defined?(@confine_collection) - @confine_collection = Puppet::Provider::ConfineCollection.new + @confine_collection = Puppet::Provider::ConfineCollection.new(self.to_s) end @confine_collection end diff --git a/spec/unit/provider/confine.rb b/spec/unit/provider/confine.rb index 867b6e6be..626f79b27 100755 --- a/spec/unit/provider/confine.rb +++ b/spec/unit/provider/confine.rb @@ -34,7 +34,10 @@ describe Puppet::Provider::Confine do end describe "when testing all values" do - before { @confine = Puppet::Provider::Confine.new(%w{a b c}) } + before do + @confine = Puppet::Provider::Confine.new(%w{a b c}) + @confine.label = "foo" + end it "should be invalid if any values fail" do @confine.stubs(:pass?).returns true @@ -51,6 +54,14 @@ describe Puppet::Provider::Confine do @confine.expects(:pass?).once.returns false @confine.valid? end + + it "should log failing confines with the label and message" do + @confine.stubs(:pass?).returns false + @confine.expects(:message).returns "My message" + @confine.expects(:label).returns "Mylabel" + Puppet.expects(:debug).with("Mylabel: My message") + @confine.valid? + end end describe "when testing the result of the values" do diff --git a/spec/unit/provider/confine_collection.rb b/spec/unit/provider/confine_collection.rb index 1598b5f99..444281c77 100755 --- a/spec/unit/provider/confine_collection.rb +++ b/spec/unit/provider/confine_collection.rb @@ -6,69 +6,81 @@ require 'puppet/provider/confine_collection' describe Puppet::Provider::ConfineCollection do it "should be able to add confines" do - Puppet::Provider::ConfineCollection.new.should respond_to(:confine) + Puppet::Provider::ConfineCollection.new("label").should respond_to(:confine) + end + + it "should require a label at initialization" do + lambda { Puppet::Provider::ConfineCollection.new }.should raise_error(ArgumentError) + end + + it "should make its label available" do + Puppet::Provider::ConfineCollection.new("mylabel").label.should == "mylabel" end describe "when creating confine instances" do it "should create an instance of the named test with the provided values" do test_class = mock 'test_class' - test_class.expects(:new).with(%w{my values}) + test_class.expects(:new).with(%w{my values}).returns(stub('confine', :label= => nil)) Puppet::Provider::Confine.expects(:test).with(:foo).returns test_class - Puppet::Provider::ConfineCollection.new.confine :foo => %w{my values} + Puppet::Provider::ConfineCollection.new("label").confine :foo => %w{my values} end - describe "and the test cannot be found" do - before do - @variable = mock 'variable_test' + it "should copy its label to the confine instance" do + confine = mock 'confine' + test_class = mock 'test_class' + test_class.expects(:new).returns confine + Puppet::Provider::Confine.expects(:test).returns test_class - Puppet::Provider::Confine.expects(:test).with(:foo).returns nil - Puppet::Provider::Confine.expects(:test).with(:variable).returns @variable - end + confine.expects(:label=).with("label") + Puppet::Provider::ConfineCollection.new("label").confine :foo => %w{my values} + end + + describe "and the test cannot be found" do it "should create a Facter test with the provided values and set the name to the test name" do - confine = mock 'confine' + confine = Puppet::Provider::Confine.test(:variable).new(%w{my values}) confine.expects(:name=).with(:foo) - @variable.expects(:new).with(%w{my values}).returns confine - Puppet::Provider::ConfineCollection.new.confine :foo => %w{my values} + confine.class.expects(:new).with(%w{my values}).returns confine + Puppet::Provider::ConfineCollection.new("label").confine(:foo => %w{my values}) end end describe "and the 'for_binary' option was provided" do it "should mark the test as a binary confine" do - confine = mock 'confine' + confine = Puppet::Provider::Confine.test(:exists).new(:bar) confine.expects(:for_binary=).with true Puppet::Provider::Confine.test(:exists).expects(:new).with(:bar).returns confine - Puppet::Provider::ConfineCollection.new.confine :exists => :bar, :for_binary => true + Puppet::Provider::ConfineCollection.new("label").confine :exists => :bar, :for_binary => true end end end it "should be valid if no confines are present" do - Puppet::Provider::ConfineCollection.new.should be_valid + Puppet::Provider::ConfineCollection.new("label").should be_valid end it "should be valid if all confines pass" do - c1 = mock 'c1', :valid? => true - c2 = mock 'c2', :valid? => true + c1 = stub 'c1', :valid? => true, :label= => nil + c2 = stub 'c2', :valid? => true, :label= => nil Puppet::Provider::Confine.test(:true).expects(:new).returns(c1) Puppet::Provider::Confine.test(:false).expects(:new).returns(c2) - confiner = Puppet::Provider::ConfineCollection.new + confiner = Puppet::Provider::ConfineCollection.new("label") confiner.confine :true => :bar, :false => :bee confiner.should be_valid end it "should not be valid if any confines fail" do - c1 = stub 'c1', :valid? => true - c2 = stub 'c2', :valid? => false + c1 = stub 'c1', :valid? => true, :label= => nil + c2 = stub 'c2', :valid? => false, :label= => nil Puppet::Provider::Confine.test(:true).expects(:new).returns(c1) Puppet::Provider::Confine.test(:false).expects(:new).returns(c2) - confiner = Puppet::Provider::ConfineCollection.new + confiner = Puppet::Provider::ConfineCollection.new("label") confiner.confine :true => :bar, :false => :bee confiner.should_not be_valid @@ -76,7 +88,7 @@ describe Puppet::Provider::ConfineCollection do describe "when providing a summary" do before do - @confiner = Puppet::Provider::ConfineCollection.new + @confiner = Puppet::Provider::ConfineCollection.new("label") end it "should return a hash" do diff --git a/spec/unit/provider/confiner.rb b/spec/unit/provider/confiner.rb index 078fc4420..0a0d67fb5 100755 --- a/spec/unit/provider/confiner.rb +++ b/spec/unit/provider/confiner.rb @@ -30,7 +30,8 @@ describe Puppet::Provider::Confiner do end it "should create a new confine collection if one does not exist" do - Puppet::Provider::ConfineCollection.expects(:new).returns "mycoll" + Puppet::Provider::ConfineCollection.expects(:new).with("mylabel").returns "mycoll" + @object.expects(:to_s).returns "mylabel" @object.confine_collection.should == "mycoll" end |
