Use anchor to require necessary packages

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

Change-Id: I9a1c691d092e03ba03287476ecbebcfcbd9b246c
This commit is contained in:
Takashi Kajinami 2020-05-04 02:30:14 +09:00
parent 16d91fc169
commit 5e8074a5b0
2 changed files with 13 additions and 2 deletions

View File

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

View File

@ -49,4 +49,15 @@ describe 'Puppet::Type.type(:zaqar_config)' do
@zaqar_config[:ensure] = :latest @zaqar_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/) }.to raise_error(Puppet::Error, /Invalid value/)
end end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'zaqar::install::end')
catalog.add_resource anchor, @zaqar_config
dependency = @zaqar_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@zaqar_config)
expect(dependency[0].source).to eq(anchor)
end
end end