Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cleanup some dumb tests in settings specs #724

Merged
merged 1 commit into from

2 participants

@cprice404
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.

@cprice404 cprice404 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 puppetlabs:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 26, 2012
  1. @cprice404

    Cleanup some dumb tests in settings specs

    cprice404 authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 5 deletions.
  1. +8 −3 lib/puppet/util/settings.rb
  2. +13 −2 spec/unit/util/settings_spec.rb
View
11 lib/puppet/util/settings.rb
@@ -18,7 +18,7 @@ class Puppet::Util::Settings
attr_accessor :files
attr_reader :timer
- ReadOnly = [:run_mode]
+ READ_ONLY_SETTINGS = [:run_mode]
# These are the settings that every app is required to specify; there are reasonable defaults defined in application.rb.
REQUIRED_APP_SETTINGS = [:run_mode, :logdir, :confdir, :vardir]
@@ -646,7 +646,7 @@ def set_value(param, value, type, options = {})
value = setting.munge(value) if setting.respond_to?(:munge)
setting.handle(value) if setting.respond_to?(:handle) and not options[:dont_trigger_handles]
- if ReadOnly.include? param and type != :application_defaults
+ if read_only_settings.include? param and type != :application_defaults
raise ArgumentError,
"You're attempting to set configuration parameter $#{param}, which is read-only."
end
@@ -791,7 +791,7 @@ def to_config
end
eachsection do |section|
persection(section) do |obj|
- str += obj.to_config + "\n" unless ReadOnly.include? obj.name or obj.name == :genconfig
+ str += obj.to_config + "\n" unless read_only_settings.include? obj.name or obj.name == :genconfig
end
end
@@ -971,6 +971,11 @@ def readwritelock(default, *args, &bloc)
private
+ # This is just here to simplify testing. This method can be stubbed easily. Constants can't.
+ def read_only_settings()
+ READ_ONLY_SETTINGS
+ end
+
def get_config_file_default(default)
obj = nil
unless obj = @config[default]
View
15 spec/unit/util/settings_spec.rb
@@ -264,8 +264,19 @@
@settings[:myval] = "memarg"
end
- it "should raise an error if we try to set 'run_mode'" do
- lambda{ @settings[:run_mode] = "foo" }.should raise_error(ArgumentError)
+ it "should raise an error if we try to set a setting that hasn't been defined'" do
+ lambda{
+ @settings[:why_so_serious] = "foo"
+ }.should raise_error(ArgumentError, /unknown configuration parameter/)
+ end
+
+ 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
+ @settings.define_settings(:section, :one => { :default => "test", :desc => "a" })
+ @settings.expects(:read_only_settings).returns([:one])
+
+ lambda{
+ @settings[:one] = "foo"
+ }.should raise_error(ArgumentError, /read-only/)
end
it "should warn and use [master] if we ask for [puppetmasterd]" do
Something went wrong with that request. Please try again.