From 5e8074a5b0489f2dc0a763556d6599d1bf643ee0 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 4 May 2020 02:30:14 +0900 Subject: [PATCH] Use anchor to require necessary packages ... so that correct packages are required without re-defining them in resource implementations. Change-Id: I9a1c691d092e03ba03287476ecbebcfcbd9b246c --- lib/puppet/type/zaqar_config.rb | 4 ++-- spec/unit/type/zaqar_config_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/puppet/type/zaqar_config.rb b/lib/puppet/type/zaqar_config.rb index ab1ecbc..45bc392 100644 --- a/lib/puppet/type/zaqar_config.rb +++ b/lib/puppet/type/zaqar_config.rb @@ -46,8 +46,8 @@ Puppet::Type.newtype(:zaqar_config) do defaultto('') end - autorequire(:package) do - 'zaqar-common' + autorequire(:anchor) do + ['zaqar::install::end'] end end diff --git a/spec/unit/type/zaqar_config_spec.rb b/spec/unit/type/zaqar_config_spec.rb index 832efcc..9978e36 100644 --- a/spec/unit/type/zaqar_config_spec.rb +++ b/spec/unit/type/zaqar_config_spec.rb @@ -49,4 +49,15 @@ describe 'Puppet::Type.type(:zaqar_config)' do @zaqar_config[:ensure] = :latest }.to raise_error(Puppet::Error, /Invalid value/) 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