Merge pull request #456 from johanfleury/cleaning/template/unattended-upgrades
[puppet-modules/puppetlabs-apt.git] / spec / defines / force_spec.rb
1 require 'spec_helper'
2 describe 'apt::force', :type => :define do
3   let(:facts) { { :lsbdistid => 'Debian' } }
4   let :pre_condition do
5     'include apt::params'
6   end
7
8   let :title do
9     'my_package'
10   end
11
12   let :default_params do
13     {
14       :release     => false,
15       :version     => false,
16       :cfg_files   => 'none',
17       :cfg_missing => false,
18     }
19   end
20
21   describe "when using default parameters" do
22     it { should contain_exec("/usr/bin/apt-get -y    install #{title}").with(
23       :unless    => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'",
24       :logoutput => 'on_failure',
25       :timeout   => '300'
26     ) }
27   end
28
29   describe "when specifying release parameter" do
30     let :params do
31       default_params.merge(:release => 'testing')
32     end
33     it { should contain_exec("/usr/bin/apt-get -y   -t #{params[:release]} install #{title}").with(
34       :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"
35     ) }
36   end
37
38   describe "when specifying version parameter" do
39     let :params do
40       default_params.merge(:version => '1')
41     end
42     it { should contain_exec("/usr/bin/apt-get -y    install #{title}=#{params[:version]}").with(
43       :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Version: #{params[:version]}'"
44     ) }
45   end
46
47   describe "when specifying cfg_files parameter" do
48     let :params do
49       default_params.merge(:cfg_files => 'unchanged')
50     end
51     it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef"   install my_package').with(
52       :unless    => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'"
53     ) }
54   end
55
56   describe "when specifying cfg_missing parameter" do
57     let :params do
58       default_params.merge(:cfg_missing => true)
59     end
60     it { should contain_exec('/usr/bin/apt-get -y  -o Dpkg::Options::="--force-confmiss"  install my_package').with(
61       :unless    => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'"
62     ) }
63   end
64
65   describe "when specifying cfg_files and cfg_missing parameter" do
66    let :params do
67      default_params.merge(
68        :cfg_files   => 'unchanged',
69        :cfg_missing => true
70      )
71    end
72    it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confmiss"  install my_package').with(
73      :unless    => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'"
74    ) }
75   end
76
77   describe "when specifying release and version parameters" do
78     let :params do
79       default_params.merge(
80         :release => 'testing',
81         :version => '1'
82       )
83     end
84     it { should contain_exec("/usr/bin/apt-get -y   -t #{params[:release]} install #{title}=1").with(
85       :unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'"
86     ) }
87   end
88
89   describe "when specifying release, version, cfg_files and cfg_missing parameters" do
90    let :params do
91      default_params.merge(
92        :release     => 'testing',
93        :version     => '1',
94        :cfg_files   => 'unchanged',
95        :cfg_missing => true
96      )
97    end
98    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(
99      :unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'"
100    ) }
101   end
102 end