X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fdefines%2Fsetting_spec.rb;h=bf361fa5984626a7ba9dea73d146dfd5e9eec8c4;hb=b87e1af3704f5574bda393e36ded542ee7c4be23;hp=5e88eea16ed90b72a6778f9c8c9b1da60d9eb442;hpb=a21c183b723ddf0cf344d2a2334786faf0f1a181;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/defines/setting_spec.rb b/spec/defines/setting_spec.rb index 5e88eea..bf361fa 100644 --- a/spec/defines/setting_spec.rb +++ b/spec/defines/setting_spec.rb @@ -2,7 +2,17 @@ require 'spec_helper' describe 'apt::setting' do let(:pre_condition) { 'class { "apt": }' } - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } + let :facts do + { + :os => { :distro => { :codename => 'wheezy' }, :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, + :lsbdistrelease => '7.0', + :lsbdistcodename => 'wheezy', + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :lsbdistid => 'Debian', + :puppetversion => Puppet.version, + } + end let(:title) { 'conf-teddybear' } let(:default_params) { { :content => 'di' } } @@ -10,31 +20,31 @@ describe 'apt::setting' do describe 'when using the defaults' do context 'without source or content' do it do - expect { is_expected.to compile }.to raise_error(Puppet::Error, /needs either of /) + expect { subject.call }.to raise_error(Puppet::Error, /needs either of /) end end context 'with title=conf-teddybear ' do let(:params) { default_params } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear') } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]') } end context 'with title=pref-teddybear' do let(:title) { 'pref-teddybear' } let(:params) { default_params } - it { is_expected.to contain_file('/etc/apt/preferences.d/50teddybear') } + it { is_expected.to contain_file('/etc/apt/preferences.d/teddybear.pref').that_notifies('Class[Apt::Update]') } end context 'with title=list-teddybear' do let(:title) { 'list-teddybear' } let(:params) { default_params } - it { is_expected.to contain_file('/etc/apt/sources.list.d/teddybear.list') } + it { is_expected.to contain_file('/etc/apt/sources.list.d/teddybear.list').that_notifies('Class[Apt::Update]') } end context 'with source' do let(:params) { { :source => 'puppet:///la/die/dah' } } it { - is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({ :ensure => 'file', :owner => 'root', :group => 'root', @@ -45,7 +55,7 @@ describe 'apt::setting' do context 'with content' do let(:params) { default_params } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({ :ensure => 'file', :owner => 'root', :group => 'root', @@ -55,11 +65,26 @@ describe 'apt::setting' do end end + describe 'settings requiring settings, MODULES-769' do + let(:pre_condition) do + 'class { "apt": } + apt::setting { "list-teddybear": content => "foo" } + ' + end + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } } + let(:title) { 'conf-teddybear' } + let(:default_params) { { :content => 'di' } } + + let(:params) { default_params.merge({ :require => 'Apt::Setting[list-teddybear]' }) } + + it { is_expected.to compile.with_all_deps } + end + describe 'when trying to pull one over' do context 'with source and content' do let(:params) { default_params.merge({ :source => 'la' }) } it do - expect { is_expected.to compile }.to raise_error(Puppet::Error, /cannot have both /) + expect { subject.call }.to raise_error(Puppet::Error, /cannot have both /) end end @@ -67,63 +92,36 @@ describe 'apt::setting' do let(:title) { 'ext-teddybear' } let(:params) { default_params } it do - expect { is_expected.to compile }.to raise_error(Puppet::Error, /must start with /) + expect { subject.call }.to raise_error(Puppet::Error, /must start with either/) end end context 'with ensure=banana' do let(:params) { default_params.merge({ :ensure => 'banana' }) } it do - expect { is_expected.to compile }.to raise_error(Puppet::Error, /"banana" does not /) + expect { subject.call }.to raise_error(Puppet::Error, /Enum\['absent', 'file', 'present'\], got 'banana'/) end end context 'with priority=1.2' do let(:params) { default_params.merge({ :priority => 1.2 }) } - it do - expect { is_expected.to compile }.to raise_error(Puppet::Error, /be an integer /) + if Puppet::Util::Package.versioncmp(Puppet.version, '4.0') >= 0 || ENV["FUTURE_PARSER"] == 'yes' + it { is_expected.to compile.and_raise_error(/expects a value of type/) } + else + it { is_expected.to compile.and_raise_error(/priority must be an integer or a zero-padded integer/) } end end end describe 'with priority=100' do let(:params) { default_params.merge({ :priority => 100 }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear') } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear').that_notifies('Class[Apt::Update]') } end describe 'with ensure=absent' do let(:params) { default_params.merge({ :ensure => 'absent' }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({ :ensure => 'absent', })} end - - describe 'with file_perms' do - context "{'owner' => 'roosevelt'}" do - let(:params) { default_params.merge({ :file_perms => {'owner' => 'roosevelt'} }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ - :owner => 'roosevelt', - :group => 'root', - :mode => '0644', - })} - end - - context "'group' => 'roosevelt'}" do - let(:params) { default_params.merge({ :file_perms => {'group' => 'roosevelt'} }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ - :owner => 'root', - :group => 'roosevelt', - :mode => '0644', - })} - end - - context "'owner' => 'roosevelt'}" do - let(:params) { default_params.merge({ :file_perms => {'mode' => '0600'} }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ - :owner => 'root', - :group => 'root', - :mode => '0600', - })} - end - end end