diff options
-rw-r--r-- | lib/puppet/provider.rb | 14 | ||||
-rwxr-xr-x | lib/puppet/provider/parsedfile.rb | 2 | ||||
-rwxr-xr-x | test/ral/providers/provider.rb | 50 |
3 files changed, 65 insertions, 1 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb index 5ab2657ba..1f18ae730 100644 --- a/lib/puppet/provider.rb +++ b/lib/puppet/provider.rb @@ -12,6 +12,12 @@ class Puppet::Provider include Puppet::Util, Puppet::Util::Docs include Puppet::Util::Logging attr_accessor :name + + # The source parameter exists so that providers using the same + # source can specify this, so reading doesn't attempt to read the + # same package multiple times. + attr_accessor :source + # LAK 2007-05-09: Keep the model stuff around for backward compatibility attr_reader :model attr_accessor :resource_type @@ -182,6 +188,14 @@ class Puppet::Provider end end + # Retrieve the data source. Defaults to the provider name. + def self.source + unless defined? @source + @source = self.name + end + @source + end + # Check whether this implementation is suitable for our platform. def self.suitable?(short = true) # A single false result is sufficient to turn the whole thing down. diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index 3a2acf85f..09233069b 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -169,7 +169,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider end # Retrieve all of the data from disk. There are three ways to know - # while files to retrieve: We might have a list of file objects already + # which files to retrieve: We might have a list of file objects already # set up, there might be instances of our associated resource and they # will have a path parameter set, and we will have a default path # set. We need to turn those three locations into a list of files, diff --git a/test/ral/providers/provider.rb b/test/ral/providers/provider.rb index fcc6aaa09..9e59f2008 100755 --- a/test/ral/providers/provider.rb +++ b/test/ral/providers/provider.rb @@ -28,6 +28,15 @@ class TestProvider < Test::Unit::TestCase return provider end + def setup + super + @type = Puppet::Type.newtype(:provider_test) do + newparam(:name) {} + ensurable + end + cleanup { Puppet::Type.rmtype(:provider_test) } + end + def test_confine provider = newprovider @@ -243,6 +252,47 @@ class TestProvider < Test::Unit::TestCase optional.missing end end + + # Disabling, since I might not keep this interface + def disabled_test_read_and_each + # Create a new provider + provider = @type.provide(:testing) + + assert_raise(Puppet::DevError, "Did not fail when :read was not overridden") do + provider.read + end + + children = [:one, :two] + provider.meta_def(:read) do + children + end + + result = [] + assert_nothing_raised("could not call 'each' on provider class") do + provider.each { |i| result << i } + end + + assert_equal(children, result, "did not get correct list from each") + + assert_equal(children, provider.collect { |i| i }, "provider does not include enumerable") + end + + def test_source + base = @type.provide(:base) + + assert_equal(:base, base.source, "source did not default correctly") + assert_equal(:base, base.source, "source did not default correctly") + + sub = @type.provide(:sub, :parent => :base) + + assert_equal(:sub, sub.source, "source did not default correctly for sub class") + assert_equal(:sub, sub.source, "source did not default correctly for sub class") + + other = @type.provide(:other, :parent => :base, :source => :base) + + assert_equal(:base, other.source, "source did not override") + assert_equal(:base, other.source, "source did not override") + end end class TestProviderFeatures < Test::Unit::TestCase |