X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fdefines%2Fforce_spec.rb;h=5c48ec64c3f41a2a89142fbc705ef20622d986d2;hb=61080fb6760e3d28b04158a3a2e1f3a055a2854e;hp=b8665e6dabe3606d414370ec38cc07ec5d449caf;hpb=450fadb86a507fc8d268aec8ab872ab502db992c;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/defines/force_spec.rb b/spec/defines/force_spec.rb index b8665e6..5c48ec6 100644 --- a/spec/defines/force_spec.rb +++ b/spec/defines/force_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' describe 'apt::force', :type => :define do - let(:facts) { { :lsbdistid => 'Debian' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } let :pre_condition do 'include apt::params' end @@ -11,27 +11,27 @@ describe 'apt::force', :type => :define do let :default_params do { - :release => 'testing', - :version => false + :release => false, + :version => false, + :cfg_files => 'none', + :cfg_missing => false, } end describe "when using default parameters" do - let :params do - default_params - end - it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}").with( - :unless => "/usr/bin/test \$(/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1", - :timeout => '300' + it { should contain_exec("/usr/bin/apt-get -y install #{title}").with( + :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'", + :logoutput => 'on_failure', + :timeout => '300' ) } end - describe "when specifying false release parameter" do + describe "when specifying release parameter" do let :params do - default_params.merge(:release => false) + default_params.merge(:release => 'testing') end - it { should contain_exec("/usr/bin/apt-get -y install #{title}").with( - :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'" + it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}").with( + :unless => "/usr/bin/test \$(/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1" ) } end @@ -39,20 +39,64 @@ describe 'apt::force', :type => :define do let :params do default_params.merge(:version => '1') end - it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}=#{params[:version]}").with( - :unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'" + it { should contain_exec("/usr/bin/apt-get -y install #{title}=#{params[:version]}").with( + :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Version: #{params[:version]}'" + ) } + end + + describe "when specifying cfg_files parameter" do + let :params do + default_params.merge(:cfg_files => 'unchanged') + end + it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" install my_package').with( + :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'" + ) } + end + + describe "when specifying cfg_missing parameter" do + let :params do + default_params.merge(:cfg_missing => true) + end + it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confmiss" install my_package').with( + :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'" ) } end - describe "when specifying false release and version parameters" do + describe "when specifying cfg_files and cfg_missing parameter" do + let :params do + default_params.merge( + :cfg_files => 'unchanged', + :cfg_missing => true + ) + end + it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confmiss" install my_package').with( + :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'" + ) } + end + + describe "when specifying release and version parameters" do let :params do default_params.merge( - :release => false, + :release => 'testing', :version => '1' ) end - it { should contain_exec("/usr/bin/apt-get -y install #{title}=1").with( - :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Version: #{params[:version]}'" + it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}=1").with( + :unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'" ) } end + + describe "when specifying release, version, cfg_files and cfg_missing parameters" do + let :params do + default_params.merge( + :release => 'testing', + :version => '1', + :cfg_files => 'unchanged', + :cfg_missing => true + ) + end + it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confmiss" -t testing install my_package=1').with( + :unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'" + ) } + end end