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