Use anchor to require necessary packages

... so that correct packages are required without re-defining them in
resource implementations.

Change-Id: Ib00bf9593a3ea05a70538758e268b85b0b8dbc3f
This commit is contained in:
Takashi Kajinami 2020-05-04 15:27:54 +09:00
parent 66f1eb0822
commit 38b523a542
2 changed files with 6 additions and 6 deletions

View File

@ -46,8 +46,8 @@ Puppet::Type.newtype(:watcher_config) do
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'watcher'
autorequire(:anchor) do
['watcher::install::end']
end
end

View File

@ -1,5 +1,6 @@
require 'puppet'
require 'puppet/type/watcher_config'
describe 'Puppet::Type.type(:watcher_config)' do
before :each do
@watcher_config = Puppet::Type.type(:watcher_config).new(:name => 'DEFAULT/foo', :value => 'bar')
@ -52,13 +53,12 @@ describe 'Puppet::Type.type(:watcher_config)' do
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'watcher')
catalog.add_resource package, @watcher_config
anchor = Puppet::Type.type(:anchor).new(:name => 'watcher::install::end')
catalog.add_resource anchor, @watcher_config
dependency = @watcher_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@watcher_config)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end