[FM-6956] Removal of unsupported OS from apt
[puppet-modules/puppetlabs-apt.git] / spec / defines / ppa_spec.rb
1 require 'spec_helper'
2 describe 'apt::ppa' do
3   let :pre_condition do
4     'class { "apt": }'
5   end
6
7   describe 'defaults' do
8     let :facts do
9       {
10         os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '41.04' } },
11         lsbdistrelease: '14.04',
12         lsbdistcodename: 'trusty',
13         operatingsystem: 'Ubuntu',
14         osfamily: 'Debian',
15         lsbdistid: 'Ubuntu',
16         puppetversion: Puppet.version,
17       }
18     end
19
20     let(:title) { 'ppa:needs/such.substitution/wow+type' }
21
22     it { is_expected.not_to contain_package('python-software-properties') }
23     it {
24       is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow+type').that_notifies('Class[Apt::Update]').with(environment: [],
25                                                                                                                                       command: '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type', # rubocop:disable Metrics/LineLength
26                                                                                                                                       unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-trusty.list', # rubocop:disable Metrics/LineLength
27                                                                                                                                       user: 'root',
28                                                                                                                                       logoutput: 'on_failure')
29     }
30   end
31
32   describe 'Ubuntu 15.10 sources.list filename' do
33     let :facts do
34       {
35         os: { family: 'Debian', name: 'Ubuntu', release: { major: '15', full: '15.10' } },
36         lsbdistrelease: '15.10',
37         lsbdistcodename: 'wily',
38         operatingsystem: 'Ubuntu',
39         osfamily: 'Debian',
40         lsbdistid: 'Ubuntu',
41         puppetversion: Puppet.version,
42       }
43     end
44
45     let(:title) { 'ppa:user/foo' }
46
47     it {
48       is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: [],
49                                                                                                               command: '/usr/bin/add-apt-repository -y ppa:user/foo',
50                                                                                                               unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list',
51                                                                                                               user: 'root',
52                                                                                                               logoutput: 'on_failure')
53     }
54   end
55
56   describe 'package_name => software-properties-common' do
57     let :pre_condition do
58       'class { "apt": }'
59     end
60     let :params do
61       {
62         package_name: 'software-properties-common',
63         package_manage: true,
64       }
65     end
66     let :facts do
67       {
68         os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
69         lsbdistrelease: '14.04',
70         lsbdistcodename: 'trusty',
71         operatingsystem: 'Ubuntu',
72         osfamily: 'Debian',
73         lsbdistid: 'Ubuntu',
74         puppetversion: Puppet.version,
75       }
76     end
77
78     let(:title) { 'ppa:needs/such.substitution/wow' }
79
80     it { is_expected.to contain_package('software-properties-common') }
81     it {
82       is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [],
83                                                                                                                                  'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', # rubocop:disable Metrics/LineLength
84                                                                                                                                  'unless'      => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list', # rubocop:disable Metrics/LineLength
85                                                                                                                                  'user'        => 'root',
86                                                                                                                                  'logoutput'   => 'on_failure')
87     }
88
89     it {
90       is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with('ensure' => 'file')
91     }
92   end
93
94   describe 'package_manage => true, multiple ppas, MODULES-2873' do
95     let :pre_condition do
96       'class { "apt": }
97        apt::ppa {"ppa:user/foo":
98          package_manage => true
99        }'
100     end
101     let :facts do
102       {
103         os: { family: 'Debian', name: 'Ubuntu', release: { major: '11', full: '11.04' } },
104         lsbdistrelease: '11.04',
105         lsbdistcodename: 'natty',
106         operatingsystem: 'Ubuntu',
107         osfamily: 'Debian',
108         lsbdistid: 'Ubuntu',
109         puppetversion: Puppet.version,
110       }
111     end
112     let :params do
113       {
114         package_manage: true,
115       }
116     end
117
118     let(:title) { 'ppa:user/bar' }
119
120     it { is_expected.to contain_package('python-software-properties') }
121     it {
122       is_expected.to contain_exec('add-apt-repository-ppa:user/bar').that_notifies('Class[Apt::Update]').with('environment' => [],
123                                                                                                               'command'     => '/usr/bin/add-apt-repository -y ppa:user/bar',
124                                                                                                               'unless'      => '/usr/bin/test -f /etc/apt/sources.list.d/user-bar-natty.list',
125                                                                                                               'user'        => 'root',
126                                                                                                               'logoutput'   => 'on_failure')
127     }
128
129     it {
130       is_expected.to contain_file('/etc/apt/sources.list.d/user-bar-natty.list').that_requires('Exec[add-apt-repository-ppa:user/bar]').with('ensure' => 'file')
131     }
132   end
133
134   describe 'package_manage => false' do
135     let :pre_condition do
136       'class { "apt": }'
137     end
138     let :facts do
139       {
140         os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
141         lsbdistrelease: '14.04',
142         lsbdistcodename: 'trusty',
143         operatingsystem: 'Ubuntu',
144         osfamily: 'Debian',
145         lsbdistid: 'Ubuntu',
146         puppetversion: Puppet.version,
147       }
148     end
149     let :params do
150       {
151         package_manage: false,
152       }
153     end
154
155     let(:title) { 'ppa:needs/such.substitution/wow' }
156
157     it { is_expected.not_to contain_package('python-software-properties') }
158     it {
159       is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [],
160                                                                                                                                  'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', # rubocop:disable Metrics/LineLength
161                                                                                                                                  'unless'      => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list', # rubocop:disable Metrics/LineLength
162                                                                                                                                  'user'        => 'root',
163                                                                                                                                  'logoutput'   => 'on_failure')
164     }
165
166     it {
167       is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with('ensure' => 'file')
168     }
169   end
170
171   describe 'apt included, no proxy' do
172     let :pre_condition do
173       'class { "apt": }
174       apt::ppa { "ppa:user/foo2": }
175       '
176     end
177     let :facts do
178       {
179         os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
180         lsbdistrelease: '14.04',
181         lsbdistcodename: 'trusty',
182         operatingsystem: 'Ubuntu',
183         lsbdistid: 'Ubuntu',
184         osfamily: 'Debian',
185         puppetversion: Puppet.version,
186       }
187     end
188     let :params do
189       {
190         options: '',
191         package_manage: true,
192         require: 'Apt::Ppa[ppa:user/foo2]',
193       }
194     end
195     let(:title) { 'ppa:user/foo' }
196
197     it { is_expected.to compile.with_all_deps }
198     it { is_expected.to contain_package('software-properties-common') }
199     it {
200       is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: [],
201                                                                                                               command: '/usr/bin/add-apt-repository  ppa:user/foo',
202                                                                                                               unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
203                                                                                                               user: 'root',
204                                                                                                               logoutput: 'on_failure')
205     }
206   end
207
208   describe 'apt included, proxy host' do
209     let :pre_condition do
210       'class { "apt":
211         proxy => { "host" => "localhost" },
212       }'
213     end
214     let :facts do
215       {
216         os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
217         lsbdistrelease: '14.04',
218         lsbdistcodename: 'trusty',
219         operatingsystem: 'Ubuntu',
220         lsbdistid: 'Ubuntu',
221         osfamily: 'Debian',
222         puppetversion: Puppet.version,
223       }
224     end
225     let :params do
226       {
227         'options' => '',
228         'package_manage' => true,
229       }
230     end
231     let(:title) { 'ppa:user/foo' }
232
233     it { is_expected.to contain_package('software-properties-common') }
234     it {
235       is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8080'],
236                                                                                                               command: '/usr/bin/add-apt-repository  ppa:user/foo',
237                                                                                                               unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
238                                                                                                               user: 'root',
239                                                                                                               logoutput: 'on_failure')
240     }
241   end
242
243   describe 'apt included, proxy host and port' do
244     let :pre_condition do
245       'class { "apt":
246         proxy => { "host" => "localhost", "port" => 8180 },
247       }'
248     end
249     let :facts do
250       {
251         os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
252         lsbdistrelease: '14.04',
253         lsbdistcodename: 'trusty',
254         operatingsystem: 'Ubuntu',
255         lsbdistid: 'Ubuntu',
256         osfamily: 'Debian',
257         puppetversion: Puppet.version,
258       }
259     end
260     let :params do
261       {
262         options: '',
263         package_manage: true,
264       }
265     end
266     let(:title) { 'ppa:user/foo' }
267
268     it { is_expected.to contain_package('software-properties-common') }
269     it {
270       is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8180'],
271                                                                                                               command: '/usr/bin/add-apt-repository  ppa:user/foo',
272                                                                                                               unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
273                                                                                                               user: 'root',
274                                                                                                               logoutput: 'on_failure')
275     }
276   end
277
278   describe 'apt included, proxy host and port and https' do
279     let :pre_condition do
280       'class { "apt":
281         proxy => { "host" => "localhost", "port" => 8180, "https" => true },
282       }'
283     end
284     let :facts do
285       {
286         os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
287         lsbdistrelease: '14.04',
288         lsbdistcodename: 'trusty',
289         operatingsystem: 'Ubuntu',
290         lsbdistid: 'Ubuntu',
291         osfamily: 'Debian',
292         puppetversion: Puppet.version,
293       }
294     end
295     let :params do
296       {
297         options: '',
298         package_manage: true,
299       }
300     end
301     let(:title) { 'ppa:user/foo' }
302
303     it { is_expected.to contain_package('software-properties-common') }
304     it {
305       is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'],
306                                                                                                               command: '/usr/bin/add-apt-repository  ppa:user/foo',
307                                                                                                               unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
308                                                                                                               user: 'root',
309                                                                                                               logoutput: 'on_failure')
310     }
311   end
312
313   describe 'ensure absent' do
314     let :pre_condition do
315       'class { "apt": }'
316     end
317     let :facts do
318       {
319         os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
320         lsbdistrelease: '14.04',
321         lsbdistcodename: 'trusty',
322         operatingsystem: 'Ubuntu',
323         lsbdistid: 'Ubuntu',
324         osfamily: 'Debian',
325         puppetversion: Puppet.version,
326       }
327     end
328     let(:title) { 'ppa:user/foo' }
329     let :params do
330       {
331         ensure: 'absent',
332       }
333     end
334
335     it {
336       is_expected.to contain_file('/etc/apt/sources.list.d/user-foo-trusty.list').that_notifies('Class[Apt::Update]').with(ensure: 'absent')
337     }
338   end
339
340   context 'with validation' do
341     describe 'no release' do
342       let :facts do
343         {
344           os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
345           lsbdistrelease: '14.04',
346           operatingsystem: 'Ubuntu',
347           lsbdistid: 'Ubuntu',
348           osfamily: 'Debian',
349           lsbdistcodeanme: nil,
350           puppetversion: Puppet.version,
351         }
352       end
353       let(:title) { 'ppa:user/foo' }
354
355       it do
356         is_expected.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required})
357       end
358     end
359
360     describe 'not ubuntu' do
361       let :facts do
362         {
363           os: { family: 'Debian', name: 'Debian', release: { major: '6', full: '6.0.7' } },
364           lsbdistrelease: '6.0.7',
365           lsbdistcodename: 'wheezy',
366           operatingsystem: 'Debian',
367           lsbdistid: 'debian',
368           osfamily: 'Debian',
369           puppetversion: Puppet.version,
370         }
371       end
372       let(:title) { 'ppa:user/foo' }
373
374       it do
375         is_expected.to raise_error(Puppet::Error, %r{not currently supported on Debian})
376       end
377     end
378   end
379 end