Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Cleanup some dumb tests in settings specs #724

Merged
merged 1 commit into from almost 2 years ago

2 participants

Chris Price Daniel Pittman
Chris Price
Owner

Patrick found a few things in the settings_spec tests that
weren't really testing what they claimed to be. Minor
fixes to account for those.

Chris Price Cleanup some dumb tests in settings specs
Patrick found a few things in the settings_spec tests that
weren't really testing what they claimed to be.  Minor
fixes to account for those.
a1a41a3
Daniel Pittman daniel-pittman merged commit a1a41a3 into from April 26, 2012
Daniel Pittman daniel-pittman closed this April 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 26, 2012
Chris Price Cleanup some dumb tests in settings specs
Patrick found a few things in the settings_spec tests that
weren't really testing what they claimed to be.  Minor
fixes to account for those.
a1a41a3
This page is out of date. Refresh to see the latest.
11  lib/puppet/util/settings.rb
@@ -18,7 +18,7 @@ class Puppet::Util::Settings
18 18
   attr_accessor :files
19 19
   attr_reader :timer
20 20
 
21  
-  ReadOnly = [:run_mode]
  21
+  READ_ONLY_SETTINGS = [:run_mode]
22 22
 
23 23
   # These are the settings that every app is required to specify; there are reasonable defaults defined in application.rb.
24 24
   REQUIRED_APP_SETTINGS = [:run_mode, :logdir, :confdir, :vardir]
@@ -646,7 +646,7 @@ def set_value(param, value, type, options = {})
646 646
 
647 647
     value = setting.munge(value) if setting.respond_to?(:munge)
648 648
     setting.handle(value) if setting.respond_to?(:handle) and not options[:dont_trigger_handles]
649  
-    if ReadOnly.include? param and type != :application_defaults
  649
+    if read_only_settings.include? param and type != :application_defaults
650 650
       raise ArgumentError,
651 651
         "You're attempting to set configuration parameter $#{param}, which is read-only."
652 652
     end
@@ -791,7 +791,7 @@ def to_config
791 791
     end
792 792
     eachsection do |section|
793 793
       persection(section) do |obj|
794  
-        str += obj.to_config + "\n" unless ReadOnly.include? obj.name or obj.name == :genconfig
  794
+        str += obj.to_config + "\n" unless read_only_settings.include? obj.name or obj.name == :genconfig
795 795
       end
796 796
     end
797 797
 
@@ -971,6 +971,11 @@ def readwritelock(default, *args, &bloc)
971 971
 
972 972
   private
973 973
 
  974
+  # This is just here to simplify testing.  This method can be stubbed easily.  Constants can't.
  975
+  def read_only_settings()
  976
+    READ_ONLY_SETTINGS
  977
+  end
  978
+
974 979
   def get_config_file_default(default)
975 980
     obj = nil
976 981
     unless obj = @config[default]
15  spec/unit/util/settings_spec.rb
@@ -264,8 +264,19 @@
264 264
       @settings[:myval] = "memarg"
265 265
     end
266 266
 
267  
-    it "should raise an error if we try to set 'run_mode'" do
268  
-      lambda{ @settings[:run_mode] = "foo" }.should raise_error(ArgumentError)
  267
+    it "should raise an error if we try to set a setting that hasn't been defined'" do
  268
+      lambda{
  269
+        @settings[:why_so_serious] = "foo"
  270
+      }.should raise_error(ArgumentError, /unknown configuration parameter/)
  271
+    end
  272
+
  273
+    it "should raise an error if we try to set a setting that is read-only (which, really, all of our settings probably should be)" do
  274
+      @settings.define_settings(:section, :one => { :default => "test", :desc => "a" })
  275
+      @settings.expects(:read_only_settings).returns([:one])
  276
+
  277
+      lambda{
  278
+        @settings[:one] = "foo"
  279
+      }.should raise_error(ArgumentError, /read-only/)
269 280
     end
270 281
 
271 282
     it "should warn and use [master] if we ask for [puppetmasterd]" do
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.