Improve apt::force tests and ensure cleanup happens consistently.
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / apt_ppa_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'apt::ppa' do
4
5   context 'reset' do
6     it 'removes ppa' do
7       shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0,1,2])
8       shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*', :acceptable_exit_codes => [0,1,2])
9     end
10   end
11
12   context 'adding a ppa that doesnt exist' do
13     it 'should work with no errors' do
14       pp = <<-EOS
15       include '::apt'
16       apt::ppa { 'ppa:canonical-kernel-team/ppa': }
17       EOS
18
19       apply_manifest(pp, :catch_failures => true)
20     end
21
22     describe 'contains the source file' do
23       it 'contains a kernel ppa source' do
24         shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0])
25       end
26     end
27   end
28
29   context 'readding a removed ppa.' do
30     it 'setup' do
31       shell('add-apt-repository -y ppa:raravena80/collectd5')
32       # This leaves a blank file
33       shell('add-apt-repository --remove ppa:raravena80/collectd5')
34     end
35
36     it 'should readd it successfully' do
37       pp = <<-EOS
38       include '::apt'
39       apt::ppa { 'ppa:raravena80/collectd5': }
40       EOS
41
42       apply_manifest(pp, :catch_failures => true)
43     end
44   end
45
46   context 'reset' do
47     it 'removes added ppas' do
48       shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*')
49       shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*')
50     end
51   end
52
53   context 'ensure' do
54     context 'present' do
55       it 'works without failure' do
56         pp = <<-EOS
57         include '::apt'
58         apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => present }
59         EOS
60
61         apply_manifest(pp, :catch_failures => true)
62       end
63
64       describe 'contains the source file' do
65         it 'contains a kernel ppa source' do
66           shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0])
67         end
68       end
69     end
70   end
71
72   context 'ensure' do
73     context 'absent' do
74       it 'works without failure' do
75         pp = <<-EOS
76         include '::apt'
77         apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => absent }
78         EOS
79
80         apply_manifest(pp, :catch_failures => true)
81       end
82
83       describe 'doesnt contain the source file' do
84         it 'fails' do
85           shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [2])
86         end
87       end
88     end
89   end
90
91   context 'release' do
92     context 'precise' do
93       it 'works without failure' do
94         pp = <<-EOS
95         include '::apt'
96         apt::ppa { 'ppa:canonical-kernel-team/ppa':
97           ensure  => present,
98           release => precise,
99         }
100         EOS
101
102         shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2])
103         apply_manifest(pp, :catch_failures => true)
104       end
105
106       describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do
107         it { should be_file }
108       end
109     end
110   end
111
112   context 'options' do
113     context '-y' do
114       it 'works without failure' do
115         pp = <<-EOS
116         include '::apt'
117         apt::ppa { 'ppa:canonical-kernel-team/ppa':
118           ensure  => present,
119           release => precise,
120           options => '-y',
121         }
122         EOS
123
124         shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2])
125         apply_manifest(pp, :catch_failures => true)
126       end
127
128       describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do
129         it { should be_file }
130       end
131     end
132   end
133
134   context 'reset' do
135     it { shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) }
136   end
137
138 end