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