From fe609807819cbf8126c3ae43cd96da7a62bce9a7 Mon Sep 17 00:00:00 2001 From: Daniele Sluijters Date: Tue, 14 Apr 2015 12:41:57 +0200 Subject: [PATCH] apt::conf: Don't require content `ensure=>absent`. --- manifests/conf.pp | 9 ++++++++- spec/defines/conf_spec.rb | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/manifests/conf.pp b/manifests/conf.pp index 2850205..da6d64e 100644 --- a/manifests/conf.pp +++ b/manifests/conf.pp @@ -1,8 +1,15 @@ define apt::conf ( - $content, + $content = undef, $ensure = present, $priority = '50', ) { + + unless $ensure == 'absent' { + unless $content { + fail('Need to pass in content parameter') + } + } + apt::setting { "conf-${name}": ensure => $ensure, priority => $priority, diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb index a7db4e6..e96f8bc 100644 --- a/spec/defines/conf_spec.rb +++ b/spec/defines/conf_spec.rb @@ -30,12 +30,23 @@ describe 'apt::conf', :type => :define do } end + describe "when creating a preference without content" do + let :params do + { + :priority => '00', + } + end + + it 'fails' do + expect { subject } .to raise_error(/pass in content/) + end + end + describe "when removing an apt preference" do let :params do { :ensure => 'absent', :priority => '00', - :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n" } end @@ -45,7 +56,6 @@ describe 'apt::conf', :type => :define do it { is_expected.to contain_file(filename).with({ 'ensure' => 'absent', - 'content' => /Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;/, 'owner' => 'root', 'group' => 'root', 'mode' => '0644',