summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/defaults.rb20
-rw-r--r--lib/puppet/module.rb9
-rw-r--r--lib/puppet/type.rb130
-rw-r--r--lib/puppet/type/file.rb6
-rwxr-xr-xlib/puppet/type/file/ensure.rb1
-rwxr-xr-xlib/puppet/type/tidy.rb4
-rw-r--r--lib/puppet/util/settings.rb25
-rwxr-xr-xspec/integration/defaults.rb12
-rwxr-xr-xspec/integration/type/file.rb2
-rwxr-xr-xspec/unit/parser/resource.rb6
-rwxr-xr-xspec/unit/type.rb147
-rw-r--r--spec/unit/type/resources.rb1
-rwxr-xr-xspec/unit/type/tidy.rb3
-rwxr-xr-xspec/unit/type/user.rb1
-rwxr-xr-xspec/unit/util/settings.rb9
-rwxr-xr-xtest/ral/manager/attributes.rb35
16 files changed, 234 insertions, 177 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 1a47b05b0..be9433d50 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -364,9 +364,9 @@ module Puppet
:desc => "Where FileBucket files are stored."
},
:ca => [true, "Wether the master should function as a certificate authority."],
- :modulepath => [ "$confdir/modules:/usr/share/puppet/modules",
- "The search path for modules as a colon-separated list of
- directories." ],
+ :modulepath => {:default => "$confdir/modules:/usr/share/puppet/modules",
+ :desc => "The search path for modules as a colon-separated list of
+ directories.", :type => :element }, # We don't want this to be considered a file, since it's multiple files.
:ssl_client_header => ["HTTP_X_CLIENT_DN", "The header containing an authenticated
client's SSL DN. Only used with Mongrel. This header must be set by the proxy
to the authenticated client's SSL DN (e.g., ``/CN=puppet.reductivelabs.com``).
@@ -501,11 +501,12 @@ module Puppet
# Plugin information.
self.setdefaults(:main,
- :pluginpath => ["$vardir/plugins",
- "Where Puppet should look for plugins. Multiple directories should
+ :pluginpath => {:default => "$vardir/plugins/",
+ :desc => "Where Puppet should look for plugins. Multiple directories should
be colon-separated, like normal PATH variables. As of 0.23.1, this
option is deprecated; download your custom libraries to the $libdir
- instead."],
+ instead.",
+ :type => :element}, # Don't consider this a file, since it's a colon-separated list.
:plugindest => ["$libdir",
"Where Puppet should store plugins that it pulls down from the central
server."],
@@ -521,15 +522,16 @@ module Puppet
# Central fact information.
self.setdefaults(:main,
- :factpath => {:default => "$vardir/facts",
+ :factpath => {:default => "$vardir/facts/",
:desc => "Where Puppet should look for facts. Multiple directories should
be colon-separated, like normal PATH variables.",
:call_on_define => true, # Call our hook with the default value, so we always get the value added to facter.
+ :type => :element, # Don't consider it a file, because it could be multiple colon-separated files
:hook => proc { |value| Facter.search(value) if Facter.respond_to?(:search) }},
- :factdest => ["$vardir/facts",
+ :factdest => ["$vardir/facts/",
"Where Puppet should store facts that it pulls down from the central
server."],
- :factsource => ["puppet://$server/facts",
+ :factsource => ["puppet://$server/facts/",
"From where to retrieve facts. The standard Puppet ``file`` type
is used for retrieval, so anything that is a valid file source can
be used here."],
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 7bf35ac18..ab1bc75bd 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -12,9 +12,14 @@ class Puppet::Module
dirs = Puppet.settings.value(:modulepath, environment).split(":")
if ENV["PUPPETLIB"]
dirs = ENV["PUPPETLIB"].split(":") + dirs
- else
end
- dirs.select do |p|
+ dirs.collect do |dir|
+ if dir !~ /^#{File::SEPARATOR}/
+ File.join(Dir.getwd, dir)
+ else
+ dir
+ end
+ end.select do |p|
p =~ /^#{File::SEPARATOR}/ && File::directory?(p)
end
end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 5739b369e..56788a6cf 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -96,10 +96,6 @@ class Type
when @validproperties.include?(attr): :property
when @paramhash.include?(attr): :param
when @@metaparamhash.include?(attr): :meta
- else
- raise Puppet::DevError,
- "Invalid attribute '%s' for class '%s'" %
- [attr, self.name]
end
end
@@ -123,30 +119,6 @@ class Type
end
end
- # A similar function but one that yields the class and type.
- # This is mainly so that setdefaults doesn't call quite so many functions.
- def self.eachattr(*ary)
- if ary.empty?
- ary = nil
- end
-
- # We have to do this in a specific order, so that defaults are
- # created in that order (e.g., providers should be set up before
- # anything else).
- allattrs.each do |name|
- next unless ary.nil? or ary.include?(name)
- if obj = @properties.find { |p| p.name == name }
- yield obj, :property
- elsif obj = @parameters.find { |p| p.name == name }
- yield obj, :param
- elsif obj = @@metaparams.find { |p| p.name == name }
- yield obj, :meta
- else
- raise Puppet::DevError, "Could not find parameter %s" % name
- end
- end
- end
-
def self.eachmetaparam
@@metaparams.each { |p| yield p.name }
end
@@ -501,13 +473,6 @@ class Type
}
end
- # If we've got a catalog, then use it to expire our data;
- # otherwise, null-op.
- def expire
- return nil unless expirer
- super
- end
-
# Let the catalog determine whether a given cached value is
# still valid or has expired.
def expirer
@@ -589,24 +554,18 @@ class Type
# For any parameters or properties that have defaults and have not yet been
# set, set them now. This method can be handed a list of attributes,
# and if so it will only set defaults for those attributes.
- def setdefaults(*ary)
- self.class.eachattr(*ary) { |klass, type|
- # not many attributes will have defaults defined, so we short-circuit
- # those away
- next unless klass.method_defined?(:default)
- next if @parameters[klass.name]
-
- next unless obj = self.newattr(klass)
-
- # We have to check for nil values, not "truth", so we allow defaults
- # to false.
- value = obj.default and ! value.nil?
- if ! value.nil?
- obj.value = value
- else
- @parameters.delete(obj.name)
- end
- }
+ def set_default(attr)
+ return unless klass = self.class.attrclass(attr)
+ return unless klass.method_defined?(:default)
+ return if @parameters.include?(klass.name)
+
+ return unless parameter = newattr(klass.name)
+
+ if value = parameter.default and ! value.nil?
+ parameter.value = value
+ else
+ @parameters.delete(parameter.name)
+ end
end
# Convert our object to a hash. This just includes properties.
@@ -658,7 +617,7 @@ class Type
###############################
# Code related to the closure-like behaviour of the resource classes.
- attr_writer :implicit
+ attr_accessor :implicit
# Is this type's name isomorphic with the object? That is, if the
# name conflicts, does it necessarily mean that the objects conflict?
@@ -1075,14 +1034,14 @@ class Type
# This should only be used directly from Ruby -- it's not used when going through
# normal Puppet usage.
def self.hash2resource(hash)
- hash = hash.inject({}) { |result, ary| result[ary[0].to_sym] = ary[1]; hash }
+ hash = hash.inject({}) { |result, ary| result[ary[0].to_sym] = ary[1]; result }
if title = hash[:title]
hash.delete(:title)
else
if self.namevar != :name
if hash.include?(:name) and hash.include?(self.namevar)
- raise ArgumentError, "Cannot provide both name and %s to resources of type %s" % [self.namevar, self.name]
+ raise Puppet::Error, "Cannot provide both name and %s to resources of type %s" % [self.namevar, self.name]
end
if title = hash[self.namevar]
hash.delete(self.namevar)
@@ -1094,13 +1053,16 @@ class Type
end
end
- if catalog = hash[:catalog]
- hash.delete(:catalog)
- end
# Now create our resource.
resource = Puppet::Resource.new(self.name, title)
- resource.catalog = catalog if catalog
+ [:catalog, :implicit].each do |attribute|
+ if value = hash[attribute]
+ hash.delete(attribute)
+ resource.send(attribute.to_s + "=", value)
+ end
+ end
+
hash.each do |param, value|
resource[param] = value
end
@@ -1950,15 +1912,12 @@ class Type
public
+ attr_reader :original_parameters
+
# initialize the type instance
def initialize(resource)
- if resource.is_a?(Puppet::TransObject)
- raise Puppet::DevError, "Got TransObject instead of Resource or hash"
- end
-
- unless resource.is_a?(Puppet::Resource)
- resource = self.class.hash2resource(resource)
- end
+ raise Puppet::DevError, "Got TransObject instead of Resource or hash" if resource.is_a?(Puppet::TransObject)
+ resource = self.class.hash2resource(resource) unless resource.is_a?(Puppet::Resource)
# The list of parameter/property instances.
@parameters = {}
@@ -1971,7 +1930,7 @@ class Type
self.title = resource.ref
end
- [:file, :line, :catalog].each do |getter|
+ [:file, :line, :catalog, :implicit].each do |getter|
setter = getter.to_s + "="
if val = resource.send(getter)
self.send(setter, val)
@@ -1980,22 +1939,32 @@ class Type
@tags = resource.tags
- # If they've provided a title but no name, then set the name now.
- unless name = resource[:name] || resource[self.class.namevar]
- self[:name] = resource.title
- end
+ @original_parameters = resource.to_hash
- found = []
- (self.class.allattrs + resource.keys).uniq.each do |attr|
+ set_default(:provider)
+ set_parameters(@original_parameters)
+
+ self.validate if self.respond_to?(:validate)
+ end
+
+ private
+
+ # Set all of the parameters from a hash, in the appropriate order.
+ def set_parameters(hash)
+ # Use the order provided by allattrs, but add in any
+ # extra attributes from the resource so we get failures
+ # on invalid attributes.
+ no_values = []
+ (self.class.allattrs + hash.keys).uniq.each do |attr|
begin
# Set any defaults immediately. This is mostly done so
# that the default provider is available for any other
# property validation.
- if resource.has_key?(attr)
- self[attr] = resource[attr]
+ if hash.has_key?(attr)
+ self[attr] = hash[attr]
else
- setdefaults(attr)
+ no_values << attr
end
rescue ArgumentError, Puppet::Error, TypeError
raise
@@ -2005,10 +1974,13 @@ class Type
raise error
end
end
-
- self.validate if self.respond_to?(:validate)
+ no_values.each do |attr|
+ set_default(attr)
+ end
end
+ public
+
# Set up all of our autorequires.
def finish
# Scheduling has to be done when the whole config is instantiated, so
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 7c9afb4ff..169dc577a 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -448,9 +448,6 @@ module Puppet
end
def initialize(hash)
- # Store a copy of the arguments for later.
- @original_arguments = hash.to_hash
-
# Used for caching clients
@clients = {}
@@ -478,7 +475,7 @@ module Puppet
# or so. Unfortunately, we don't have a straightforward way to manage
# the different lifetimes of this data, so we kludge it like this.
# The right-side hash wins in the merge.
- options = @original_arguments.merge(:path => full_path, :implicit => true).reject { |param, value| value.nil? }
+ options = @original_parameters.merge(:path => full_path, :implicit => true).reject { |param, value| value.nil? }
# These should never be passed to our children.
[:parent, :ensure, :recurse, :target].each do |param|
@@ -683,6 +680,7 @@ module Puppet
else
self.fail "Could not back up files of type %s" % s.ftype
end
+ expire
end
# a wrapper method to make sure the file exists before doing anything
diff --git a/lib/puppet/type/file/ensure.rb b/lib/puppet/type/file/ensure.rb
index 026d13fae..ae7137264 100755
--- a/lib/puppet/type/file/ensure.rb
+++ b/lib/puppet/type/file/ensure.rb
@@ -163,6 +163,7 @@ module Puppet
end
def sync
+ expire
@resource.remove_existing(self.should)
if self.should == :absent
return :file_removed
diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb
index f0425d2bb..9280e4a2b 100755
--- a/lib/puppet/type/tidy.rb
+++ b/lib/puppet/type/tidy.rb
@@ -255,9 +255,9 @@ Puppet::Type.newtype(:tidy) do
dir = File.dirname(path)
next unless resource = files_by_name[dir]
if resource[:require]
- resource[:require] << [:file, path]
+ resource[:require] << Puppet::Resource::Reference.new(:file, path)
else
- resource[:require] = [[:file, path]]
+ resource[:require] = [Puppet::Resource::Reference.new(:file, path)]
end
end
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index 184530cc7..9cc05d891 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -378,15 +378,22 @@ class Puppet::Util::Settings
if hash[:section]
hash[:section] = symbolize(hash[:section])
end
- case hash[:default]
- when true, false, "true", "false":
- klass = CBoolean
- when /^\$\w+\//, /^\//:
- klass = CFile
- when String, Integer, Float: # nothing
- klass = CElement
+ if type = hash[:type]
+ unless klass = {:element => CElement, :file => CFile, :boolean => CBoolean}[type]
+ raise ArgumentError, "Invalid setting type '%s'" % type
+ end
+ hash.delete(:type)
else
- raise Puppet::Error, "Invalid value '%s' for %s" % [value.inspect, hash[:name]]
+ case hash[:default]
+ when true, false, "true", "false":
+ klass = CBoolean
+ when /^\$\w+\//, /^\//:
+ klass = CFile
+ when String, Integer, Float: # nothing
+ klass = CElement
+ else
+ raise Puppet::Error, "Invalid value '%s' for %s" % [value.inspect, hash[:name]]
+ end
end
hash[:settings] = self
element = klass.new(hash)
@@ -512,8 +519,8 @@ class Puppet::Util::Settings
@config.values.find_all { |value| value.is_a?(CFile) }.each do |file|
next unless (sections.nil? or sections.include?(file.section))
- next if catalog.resource(:file, value(file.name))
next unless resource = file.to_resource
+ next if catalog.resource(resource.ref)
catalog.add_resource(resource)
end
diff --git a/spec/integration/defaults.rb b/spec/integration/defaults.rb
index efe6db1d5..b3f3a7066 100755
--- a/spec/integration/defaults.rb
+++ b/spec/integration/defaults.rb
@@ -71,4 +71,16 @@ describe "Puppet defaults" do
Puppet.settings[:bindaddress] = "192.168.0.1"
Puppet.settings[:bindaddress].should == "192.168.0.1"
end
+
+ [:factdest, :pluginpath].each do |setting|
+ it "should force the #{setting} to be a directory" do
+ Puppet.settings[setting].should =~ /\/$/
+ end
+ end
+
+ [:modulepath, :pluginpath, :factpath].each do |setting|
+ it "should configure '#{setting}' not to be a file setting, so multi-directory settings are acceptable" do
+ Puppet.settings.element(setting).should be_instance_of(Puppet::Util::Settings::CElement)
+ end
+ end
end
diff --git a/spec/integration/type/file.rb b/spec/integration/type/file.rb
index 5f15aa55c..b6b824008 100755
--- a/spec/integration/type/file.rb
+++ b/spec/integration/type/file.rb
@@ -183,7 +183,7 @@ describe Puppet::Type.type(:file) do
File.open(source, "w") { |f| f.print "foo" }
- file = Puppet::Type::File.create(:name => dest, :source => source)
+ file = Puppet::Type::File.create(:path => dest, :source => source)
catalog = Puppet::Resource::Catalog.new
catalog.add_resource file
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index e778dc8e4..648f3a6b4 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -379,7 +379,11 @@ describe Puppet::Parser::Resource do
end
it "should copy over all of the parameters" do
- @parser_resource.to_resource.to_hash.should == {:foo => "bar", :fee => "fum"}
+ result = @parser_resource.to_resource.to_hash
+
+ # The name will be in here, also.
+ result[:foo].should == "bar"
+ result[:fee].should == "fum"
end
it "should copy over the tags" do
diff --git a/spec/unit/type.rb b/spec/unit/type.rb
index c65a25c7d..58c652d2d 100755
--- a/spec/unit/type.rb
+++ b/spec/unit/type.rb
@@ -34,47 +34,99 @@ describe Puppet::Type do
resource.parameter(:fstype).must be_instance_of(Puppet::Type.type(:mount).attrclass(:fstype))
end
+ it "should have a method for setting default values for resources" do
+ Puppet::Type.type(:mount).create(:name => "foo").should respond_to(:set_default)
+ end
+
+ it "should do nothing for attributes that have no defaults and no specified value" do
+ Puppet::Type.type(:mount).create(:name => "foo").parameter(:noop).should be_nil
+ end
+
describe "when initializing" do
- it "should fail when passed a TransObject" do
- trans = Puppet::TransObject.new("/foo", :mount)
- lambda { Puppet::Type.type(:mount).new(trans) }.should raise_error(Puppet::DevError)
+ describe "and passed a TransObject" do
+ it "should fail" do
+ trans = Puppet::TransObject.new("/foo", :mount)
+ lambda { Puppet::Type.type(:mount).new(trans) }.should raise_error(Puppet::DevError)
+ end
end
- it "should create a Resource instance and use it to configure the RAL resource if passed a hash" do
- resource = Puppet::Resource.new(:mount, "/foo")
- Puppet::Resource.expects(:new).with(:mount, "/foo").returns resource
- Puppet::Type.type(:mount).new(:name => "/foo")
- end
+ describe "and passed a Puppet::Resource instance" do
+ it "should set its title to the title of the resource if the resource type is equal to the current type" do
+ resource = Puppet::Resource.new(:mount, "/foo", :name => "/other")
+ Puppet::Type.type(:mount).new(resource).title.should == "/foo"
+ end
- it "should set its title to the title of the resource if the resource type is equal to the current type" do
- resource = Puppet::Resource.new(:mount, "/foo", :name => "/other")
- Puppet::Type.type(:mount).new(resource).title.should == "/foo"
- end
+ it "should set its title to the resource reference if the resource type is not equal to the current type" do
+ resource = Puppet::Resource.new(:file, "/foo")
+ Puppet::Type.type(:mount).new(resource).title.should == "File[/foo]"
+ end
- it "should set its title to the resource reference if the resource type is not equal to the current type" do
- resource = Puppet::Resource.new(:file, "/foo")
- Puppet::Type.type(:mount).new(resource).title.should == "File[/foo]"
- end
+ [:line, :file, :catalog, :implicit].each do |param|
+ it "should copy '#{param}' from the resource if present" do
+ resource = Puppet::Resource.new(:mount, "/foo")
+ resource.send(param.to_s + "=", "foo")
+ resource.send(param.to_s + "=", "foo")
+ Puppet::Type.type(:mount).new(resource).send(param).should == "foo"
+ end
+ end
- [:line, :file, :catalog].each do |param|
- it "should copy #{param} from the resource if present" do
+ it "should copy any tags from the resource" do
resource = Puppet::Resource.new(:mount, "/foo")
- resource.send(param.to_s + "=", "foo")
- Puppet::Type.type(:mount).new(resource).send(param).should == "foo"
+ resource.tag "one", "two"
+ tags = Puppet::Type.type(:mount).new(resource).tags
+ tags.should be_include("one")
+ tags.should be_include("two")
+ end
+
+ it "should copy the resource's parameters as its own" do
+ resource = Puppet::Resource.new(:mount, "/foo", :atboot => true, :fstype => "boo")
+ params = Puppet::Type.type(:mount).new(resource).to_hash
+ params[:fstype].should == "boo"
+ params[:atboot].should == true
end
end
- it "should copy any tags from the resource" do
- resource = Puppet::Resource.new(:mount, "/foo")
- resource.tag "one", "two"
- tags = Puppet::Type.type(:mount).new(resource).tags
- tags.should be_include("one")
- tags.should be_include("two")
+ describe "and passed a Hash" do
+ it "should extract the title from the hash" do
+ Puppet::Type.type(:mount).new(:title => "/yay").title.should == "/yay"
+ end
+
+ it "should work when hash keys are provided as strings" do
+ Puppet::Type.type(:mount).new("title" => "/yay").title.should == "/yay"
+ end
+
+ it "should work when hash keys are provided as symbols" do
+ Puppet::Type.type(:mount).new(:title => "/yay").title.should == "/yay"
+ end
+
+ it "should use the name from the hash as the title if no explicit title is provided" do
+ Puppet::Type.type(:mount).new(:name => "/yay").title.should == "/yay"
+ end
+
+ it "should use the Resource Type's namevar to determine how to find the name in the hash" do
+ Puppet::Type.type(:file).new(:path => "/yay").title.should == "/yay"
+ end
+
+ it "should fail if the namevar is not equal to :name and both :name and the namevar are provided" do
+ lambda { Puppet::Type.type(:file).new(:path => "/yay", :name => "/foo") }.should raise_error(Puppet::Error)
+ @type.stubs(:namevar).returns :myname
+ end
+
+ [:catalog, :implicit].each do |param|
+ it "should extract '#{param}' from the hash if present" do
+ Puppet::Type.type(:mount).new(:name => "/yay", param => "foo").send(param).should == "foo"
+ end
+ end
+
+ it "should use any remaining hash keys as its parameters" do
+ resource = Puppet::Type.type(:mount).new(:title => "/foo", :catalog => "foo", :atboot => true, :fstype => "boo")
+ resource[:fstype].must == "boo"
+ resource[:atboot].must == true
+ end
end
it "should fail if any invalid attributes have been provided" do
- resource = Puppet::Resource.new(:mount, "/foo", :nosuchattr => "foo")
- lambda { Puppet::Type.type(:mount).new(resource) }.should raise_error(Puppet::Error)
+ lambda { Puppet::Type.type(:mount).new(:title => "/foo", :nosuchattr => "whatever") }.should raise_error(Puppet::Error)
end
it "should set its name to the resource's title if the resource does not have a :name or namevar parameter set" do
@@ -83,6 +135,10 @@ describe Puppet::Type do
Puppet::Type.type(:mount).new(resource).name.should == "/foo"
end
+ it "should fail if no title, name, or namevar are provided" do
+ lambda { Puppet::Type.type(:file).new(:atboot => true) }.should raise_error(Puppet::Error)
+ end
+
it "should set the attributes in the order returned by the class's :allattrs method" do
Puppet::Type.type(:mount).stubs(:allattrs).returns([:name, :atboot, :noop])
resource = Puppet::Resource.new(:mount, "/foo", :name => "myname", :atboot => "myboot", :noop => "whatever")
@@ -96,18 +152,41 @@ describe Puppet::Type do
Puppet::Type.type(:mount).new(resource)
- set.should == [:name, :atboot, :noop]
+ set[1..-1].should == [:name, :atboot, :noop]
+ end
+
+ it "should always set the default provider before anything else" do
+ Puppet::Type.type(:mount).stubs(:allattrs).returns([:provider, :name, :atboot])
+ resource = Puppet::Resource.new(:mount, "/foo", :name => "myname", :atboot => "myboot")
+
+ set = []
+
+ Puppet::Type.type(:mount).any_instance.stubs(:newattr).with do |param, hash|
+ set << param
+ true
+ end
+
+ Puppet::Type.type(:mount).new(resource)
+ set[0].should == :provider
end
# This one is really hard to test :/
it "should each default immediately if no value is provided" do
defaults = []
- Puppet::Type.type(:package).any_instance.stubs(:setdefaults).with { |value| defaults << value; true }
+ Puppet::Type.type(:package).any_instance.stubs(:set_default).with { |value| defaults << value; true }
Puppet::Type.type(:package).new :name => "whatever"
defaults[0].should == :provider
end
+
+ it "should retain a copy of the originally provided parameters" do
+ Puppet::Type.type(:mount).new(:name => "foo", :atboot => true, :noop => false).original_parameters.should == {:name => "foo", :atboot => true, :noop => false}
+ end
+
+ it "should store the name via the namevar in the originally provided parameters" do
+ Puppet::Type.type(:file).new(:name => "/foo").original_parameters[:path].should == "/foo"
+ end
end
it "should have a class method for converting a hash into a Puppet::Resource instance" do
@@ -136,11 +215,13 @@ describe Puppet::Type do
it "should fail if the namevar is not equal to :name and both :name and the namevar are provided" do
@type.stubs(:namevar).returns :myname
- lambda { @type.hash2resource(:myname => "foo", :name => 'bar') }.should raise_error(ArgumentError)
+ lambda { @type.hash2resource(:myname => "foo", :name => 'bar') }.should raise_error(Puppet::Error)
end
- it "should use any provided catalog" do
- @type.hash2resource(:name => "foo", :catalog => "eh").catalog.should == "eh"
+ [:catalog, :implicit].each do |attr|
+ it "should use any provided #{attr}" do
+ @type.hash2resource(:name => "foo", attr => "eh").send(attr).should == "eh"
+ end
end
it "should set all provided parameters on the resource" do
diff --git a/spec/unit/type/resources.rb b/spec/unit/type/resources.rb
index 70bc21b5d..414af2839 100644
--- a/spec/unit/type/resources.rb
+++ b/spec/unit/type/resources.rb
@@ -8,6 +8,7 @@ resources = Puppet::Type.type(:resources)
describe resources do
describe "when initializing" do
it "should fail if the specified resource type does not exist" do
+ Puppet::Type.stubs(:type).with("Resources").returns resources
Puppet::Type.expects(:type).with("nosuchtype").returns nil
lambda { resources.create :name => "nosuchtype" }.should raise_error(Puppet::Error)
end
diff --git a/spec/unit/type/tidy.rb b/spec/unit/type/tidy.rb
index c1cb8eabf..acbbd141d 100755
--- a/spec/unit/type/tidy.rb
+++ b/spec/unit/type/tidy.rb
@@ -365,7 +365,8 @@ describe Puppet::Type.type(:tidy) do
"/what/ever/one/subone" => ["/what/ever/one/subone/ssone"]
}.each do |parent, children|
children.each do |child|
- result[parent][:require].should be_include([:file, child])
+ ref = Puppet::Resource::Reference.new(:file, child)
+ result[parent][:require].find { |req| req.to_s == ref.to_s }.should_not be_nil
end
end
end
diff --git a/spec/unit/type/user.rb b/spec/unit/type/user.rb
index 51b38186a..caf932678 100755
--- a/spec/unit/type/user.rb
+++ b/spec/unit/type/user.rb
@@ -71,7 +71,6 @@ describe user do
describe "when retrieving all current values" do
before do
@user = user.create(:name => "foo", :uid => 10, :gid => 10)
- @properties = {}
end
it "should return a hash containing values for all set properties" do
diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb
index 3bc2e6d60..0b43eeb96 100755
--- a/spec/unit/util/settings.rb
+++ b/spec/unit/util/settings.rb
@@ -46,6 +46,15 @@ describe Puppet::Util::Settings do
@settings.setdefaults(:section, :myvalue => {:default => "w", :desc => "b", :short => "m"})
end
+ it "should support specifying the setting type" do
+ @settings.setdefaults(:section, :myvalue => {:default => "w", :desc => "b", :type => :element})
+ @settings.element(:myvalue).should be_instance_of(Puppet::Util::Settings::CElement)
+ end
+
+ it "should fail if an invalid setting type is specified" do
+ lambda { @settings.setdefaults(:section, :myvalue => {:default => "w", :desc => "b", :type => :foo}) }.should raise_error(ArgumentError)
+ end
+
it "should fail when short names conflict" do
@settings.setdefaults(:section, :myvalue => {:default => "w", :desc => "b", :short => "m"})
lambda { @settings.setdefaults(:section, :myvalue => {:default => "w", :desc => "b", :short => "m"}) }.should raise_error(ArgumentError)
diff --git a/test/ral/manager/attributes.rb b/test/ral/manager/attributes.rb
index e2a61f447..0fd712e51 100755
--- a/test/ral/manager/attributes.rb
+++ b/test/ral/manager/attributes.rb
@@ -139,41 +139,6 @@ class TestTypeAttributes < Test::Unit::TestCase
end
end
- def test_setdefaults
- type = mktype
- type.newparam(:name) {}
-
- # Make one of each param type
- {
- :meta2 => :newmetaparam, :param2 => :newparam, :prop2 => :newproperty
- }.each do |name, method|
- assert_nothing_raised("Could not make %s of type %s" % [name, method]) do
- type.send(method, name) do
- defaultto "testing"
- end
- end
- end
-
- inst = type.create(:name => 'yay')
- assert_nothing_raised do
- inst.setdefaults
- end
-
- [:meta2, :param2, :prop2].each do |name|
- assert(inst.value(name), "did not get a value for %s" % name)
- end
-
- # Try a default of "false"
- type.newparam(:falsetest) do
- defaultto false
- end
-
- assert_nothing_raised do
- inst.setdefaults
- end
- assert_equal(false, inst[:falsetest], "false default was not set")
- end
-
def test_alias_parameter
type = mktype
type.newparam(:name) {}