X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fdefines%2Fsetting_spec.rb;h=b109ea6b6b499834f0ac0a6ae7472f6f55136c2a;hb=48152d4a89f17a06ddae5ac5dba774bed8a8a887;hp=3736dc9641e2d9238f51c9dcdacb1d36cc565030;hpb=4f4d8aeafdb413e9407359d19ddcb7a0de08e9fe;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/defines/setting_spec.rb b/spec/defines/setting_spec.rb index 3736dc9..b109ea6 100644 --- a/spec/defines/setting_spec.rb +++ b/spec/defines/setting_spec.rb @@ -2,44 +2,39 @@ require 'spec_helper' describe 'apt::setting' do let(:pre_condition) { 'class { "apt": }' } - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } - let(:title) { 'teddybear' } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } } + let(:title) { 'conf-teddybear' } - let(:default_params) { { :setting_type => 'conf', :content => 'di' } } + let(:default_params) { { :content => 'di' } } describe 'when using the defaults' do - context 'without setting_type' do - it do - expect { should compile }.to raise_error(Puppet::Error, /Must pass setting_type /) - end - end - context 'without source or content' do - let(:params) { { :setting_type => 'conf' } } it do - expect { should compile }.to raise_error(Puppet::Error, /needs either of /) + expect { subject.call }.to raise_error(Puppet::Error, /needs either of /) end end - context 'with setting_type=conf' do + context 'with title=conf-teddybear ' do let(:params) { default_params } - it { should contain_file('/etc/apt/apt.conf.d/50teddybear') } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]') } end - context 'with setting_type=pref' do - let(:params) { { :setting_type => 'pref', :content => 'di' } } - it { should contain_file('/etc/apt/preferences.d/50teddybear') } + 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').that_notifies('Exec[apt_update]') } end - context 'with setting_type=list' do - let(:params) { { :setting_type => 'list', :content => 'di' } } - it { should contain_file('/etc/apt/sources.list.d/teddybear.list') } + 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').that_notifies('Exec[apt_update]') } end context 'with source' do - let(:params) { { :setting_type => 'conf', :source => 'puppet:///la/die/dah' } } + let(:params) { { :source => 'puppet:///la/die/dah' } } it { - should contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ :ensure => 'file', :owner => 'root', :group => 'root', @@ -50,7 +45,7 @@ describe 'apt::setting' do context 'with content' do let(:params) { default_params } - it { should contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ :ensure => 'file', :owner => 'root', :group => 'root', @@ -60,74 +55,61 @@ 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 { should compile }.to raise_error(Puppet::Error, /cannot have both /) + expect { subject.call }.to raise_error(Puppet::Error, /cannot have both /) end end - context 'with setting_type=ext' do - let(:params) { default_params.merge({ :setting_type => 'ext' }) } + context 'with title=ext-teddybear' do + let(:title) { 'ext-teddybear' } + let(:params) { default_params } it do - expect { should compile }.to raise_error(Puppet::Error, /"ext" does not /) + expect { subject.call }.to raise_error(Puppet::Error, /must start with /) end end context 'with ensure=banana' do let(:params) { default_params.merge({ :ensure => 'banana' }) } it do - expect { should compile }.to raise_error(Puppet::Error, /"banana" does not /) + expect { subject.call }.to raise_error(Puppet::Error, /"banana" does not /) end end context 'with priority=1.2' do let(:params) { default_params.merge({ :priority => 1.2 }) } it do - expect { should compile }.to raise_error(Puppet::Error, /be an integer /) + expect { subject.call }.to raise_error(Puppet::Error, /be an integer /) end end end describe 'with priority=100' do let(:params) { default_params.merge({ :priority => 100 }) } - it { should contain_file('/etc/apt/apt.conf.d/100teddybear') } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear').that_notifies('Exec[apt_update]') } end describe 'with ensure=absent' do let(:params) { default_params.merge({ :ensure => 'absent' }) } - it { should contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[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 { should 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 { should 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 { should contain_file('/etc/apt/apt.conf.d/50teddybear').with({ - :owner => 'root', - :group => 'root', - :mode => '0600', - })} - end - end end