Improve apt::force tests and ensure cleanup happens consistently.
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / force_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'apt::force define' do
4   context 'defaults' do
5     it 'should work with no errors' do
6       pp = <<-EOS
7       include apt
8       apt::force { 'vim': }
9       EOS
10
11       shell('apt-get remove -y vim')
12       apply_manifest(pp, :catch_failures => true)
13     end
14
15     describe package('vim') do
16       it { should be_installed }
17     end
18   end
19
20   context 'release' do
21     it 'should work with no errors' do
22       pp = <<-EOS
23       include apt
24       apt::force { 'vim': release => 'precise' }
25       EOS
26
27       shell('apt-get remove -y vim')
28       apply_manifest(pp, :catch_failures => true) do |r|
29         expect(r.stdout).to match(/apt-get -y -t precise install vim/)
30       end
31     end
32
33     describe package('vim') do
34       it { should be_installed }
35     end
36   end
37
38   context 'version' do
39     it 'should work with no errors' do
40       pp = <<-EOS
41       include apt
42       apt::force { 'vim': version => '1.1.1' }
43       EOS
44
45       shell('apt-get remove -y vim')
46       apply_manifest(pp, :catch_failures => false) do |r|
47         expect(r.stdout).to match(/apt-get -y  install vim=1.1.1/)
48       end
49     end
50
51     describe package('vim') do
52       it { should_not be_installed }
53     end
54   end
55
56   context 'timeout' do
57     it 'should work with no errors' do
58       pp = <<-EOS
59       include apt
60       apt::force { 'tomcat7': timeout => '1' }
61       EOS
62
63       shell('apt-get clean')
64       apply_manifest(pp, :expect_failures => true) do |r|
65         expect(r.stderr).to match(/Error: Command exceeded timeout/)
66       end
67     end
68
69     describe package('vim') do
70       it { should_not be_installed }
71     end
72   end
73
74 end