summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2009-12-21 17:05:47 -0800
committerJames Turnbull <james@lovedthanlost.net>2010-03-25 16:16:42 +1100
commitfbedb999e4f4cc8020bc6be4a1d8868368c3ed7f (patch)
tree4812ea152b9f54fd57a5399b0c963cefda0efb80
parent389c77b1927a95e8e991ecddd1767698547a78b8 (diff)
downloadpuppet-fbedb999e4f4cc8020bc6be4a1d8868368c3ed7f.tar.gz
puppet-fbedb999e4f4cc8020bc6be4a1d8868368c3ed7f.tar.xz
puppet-fbedb999e4f4cc8020bc6be4a1d8868368c3ed7f.zip
Fixing #3148 Settings#without_noop when run with no noop setting
Some tests didn't define this setting which caused this method to fail. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
-rw-r--r--lib/puppet/util/settings.rb11
-rwxr-xr-xspec/unit/util/settings.rb23
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index df07d5c51..532fce960 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -67,7 +67,7 @@ class Puppet::Util::Settings
unsafe_clear(exceptcli)
end
end
-
+
# Remove all set values, potentially skipping cli values.
def unsafe_clear(exceptcli = false)
@values.each do |name, values|
@@ -162,6 +162,13 @@ class Puppet::Util::Settings
set_value(str, value, :cli)
end
+ def without_noop
+ old_noop = value(:noop,:cli) and set_value(:noop, false, :cli) if valid?(:noop)
+ yield
+ ensure
+ set_value(:noop, old_noop, :cli) if valid?(:noop)
+ end
+
def include?(name)
name = name.intern if name.is_a? String
@config.include?(name)
@@ -675,7 +682,7 @@ Generated on #{Time.now}.
end
throw :foundval, nil
end
-
+
# If we didn't get a value, use the default
val = @config[param].default if val.nil?
diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb
index 56428132d..645b54366 100755
--- a/spec/unit/util/settings.rb
+++ b/spec/unit/util/settings.rb
@@ -1018,4 +1018,27 @@ describe Puppet::Util::Settings do
it "should cache the result"
end
+
+ describe "#without_noop" do
+ before do
+ @settings = Puppet::Util::Settings.new
+ @settings.setdefaults :main, :noop => [true, ""]
+ end
+
+ it "should set noop to false for the duration of the block" do
+ @settings.without_noop { @settings.value(:noop, :cli).should be_false }
+ end
+
+ it "should ensure that noop is returned to its previous value" do
+ @settings.without_noop { raise } rescue nil
+ @settings.value(:noop, :cli).should be_true
+ end
+
+ it "should work even if no 'noop' setting is available" do
+ settings = Puppet::Util::Settings.new
+ stuff = nil
+ settings.without_noop { stuff = "yay" }
+ stuff.should == "yay"
+ end
+ end
end