(FM-6273) - Removing Debian 6
[puppet-modules/puppetlabs-apt.git] / spec / defines / source_spec.rb
1 require 'spec_helper'
2
3 describe 'apt::source' do
4   GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'
5
6   let :pre_condition do
7     'class { "apt": }'
8   end
9
10   let :title do
11     'my_source'
12   end
13
14   context 'defaults' do
15     context 'without location' do
16       let :facts do
17         {
18           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
19           :osfamily        => 'Debian',
20           :lsbdistcodename => 'wheezy',
21           :puppetversion   => Puppet.version,
22         }
23       end
24       it do
25         expect {
26           subject.call
27         }.to raise_error(Puppet::Error, /source entry without specifying a location/)
28       end
29     end
30     context 'with location' do
31       let :facts do
32         {
33           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
34           :lsbdistid       => 'Debian',
35           :lsbdistcodename => 'wheezy',
36           :osfamily        => 'Debian',
37           :puppetversion   => Puppet.version,
38         }
39       end
40       let(:params) { { :location => 'hello.there', } }
41
42       it { is_expected.to contain_apt__setting('list-my_source').with({
43         :ensure  => 'present',
44       }).without_content(/# my_source\ndeb-src hello.there wheezy main\n/)
45       }
46     end
47   end
48
49   describe 'no defaults' do
50     let :facts do
51       {
52         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
53         :lsbdistid       => 'Debian',
54         :lsbdistcodename => 'wheezy',
55         :osfamily        => 'Debian',
56         :operatingsystem => 'Debian',
57         :lsbdistrelease  => '7.0',
58         :puppetversion   => Puppet.version,
59       }
60     end
61
62     context 'with complex pin' do
63       let :params do
64         {
65           :location => 'hello.there',
66           :pin      => { 'release'     => 'wishwash',
67                          'explanation' => 'wishwash',
68                          'priority'    => 1001, },
69         }
70       end
71
72       it { is_expected.to contain_apt__setting('list-my_source').with({
73         :ensure => 'present',
74       }).with_content(/hello.there wheezy main\n/)
75       }
76
77       it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]')}
78
79       it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
80         :ensure       => 'present',
81         :priority     => 1001,
82         :explanation  => 'wishwash',
83         :release      => 'wishwash',
84       })
85       }
86     end
87
88     context 'with simple key' do
89       let :params do
90         {
91           :comment           => 'foo',
92           :location          => 'http://debian.mirror.iweb.ca/debian/',
93           :release           => 'sid',
94           :repos             => 'testing',
95           :key               => GPG_KEY_ID,
96           :pin               => '10',
97           :architecture      => 'x86_64',
98           :allow_unsigned    => true,
99         }
100       end
101
102       it { is_expected.to contain_apt__setting('list-my_source').with({
103         :ensure => 'present',
104       }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
105       }
106
107       it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
108         :ensure   => 'present',
109         :priority => '10',
110         :origin   => 'debian.mirror.iweb.ca',
111       })
112       }
113
114       it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
115         :ensure  => 'present',
116         :id      => GPG_KEY_ID,
117       })
118       }
119     end
120
121     context 'with complex key' do
122       let :params do
123         {
124           :comment           => 'foo',
125           :location          => 'http://debian.mirror.iweb.ca/debian/',
126           :release           => 'sid',
127           :repos             => 'testing',
128           :key               => { 'id' => GPG_KEY_ID, 'server' => 'pgp.mit.edu',
129                                   'content' => 'GPG key content',
130                                   'source'  => 'http://apt.puppetlabs.com/pubkey.gpg',},
131           :pin               => '10',
132           :architecture      => 'x86_64',
133           :allow_unsigned    => true,
134         }
135       end
136
137       it { is_expected.to contain_apt__setting('list-my_source').with({
138         :ensure => 'present',
139       }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
140       }
141
142       it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
143         :ensure   => 'present',
144         :priority => '10',
145         :origin   => 'debian.mirror.iweb.ca',
146       })
147       }
148
149       it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
150         :ensure  => 'present',
151         :id      => GPG_KEY_ID,
152         :server  => 'pgp.mit.edu',
153         :content => 'GPG key content',
154         :source  => 'http://apt.puppetlabs.com/pubkey.gpg',
155       })
156       }
157     end
158
159     context 'with simple key' do
160       let :params do
161         {
162           :comment        => 'foo',
163           :location       => 'http://debian.mirror.iweb.ca/debian/',
164           :release        => 'sid',
165           :repos          => 'testing',
166           :key            => GPG_KEY_ID,
167           :pin            => '10',
168           :architecture   => 'x86_64',
169           :allow_unsigned => true,
170         }
171       end
172
173       it { is_expected.to contain_apt__setting('list-my_source').with({
174         :ensure => 'present',
175       }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
176       }
177
178       it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
179         :ensure   => 'present',
180         :priority => '10',
181         :origin   => 'debian.mirror.iweb.ca',
182       })
183       }
184
185       it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
186         :ensure  => 'present',
187         :id      => GPG_KEY_ID,
188       })
189       }
190     end
191   end
192
193   context 'allow_unsigned true' do
194     let :facts do
195       {
196         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
197         :lsbdistid       => 'Debian',
198         :lsbdistcodename => 'wheezy',
199         :osfamily        => 'Debian',
200         :puppetversion   => Puppet.version,
201       }
202     end
203     let :params do
204       {
205         :location       => 'hello.there',
206         :allow_unsigned => true,
207       }
208     end
209
210     it { is_expected.to contain_apt__setting('list-my_source').with({
211       :ensure => 'present',
212     }).with_content(/# my_source\ndeb \[trusted=yes\] hello.there wheezy main\n/)
213     }
214   end
215
216   context 'architecture equals x86_64' do
217     let :facts do
218       {
219         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
220         :lsbdistid       => 'Debian',
221         :lsbdistcodename => 'wheezy',
222         :osfamily        => 'Debian',
223         :puppetversion   => Puppet.version,
224       }
225     end
226     let :params do
227       {
228         :location     => 'hello.there',
229         :include      => {'deb' => false, 'src' => true},
230         :architecture => 'x86_64',
231       }
232     end
233
234     it { is_expected.to contain_apt__setting('list-my_source').with({
235       :ensure => 'present',
236     }).with_content(/# my_source\ndeb-src \[arch=x86_64\] hello.there wheezy main\n/)
237     }
238   end
239
240   context 'with architecture fact and unset architecture parameter' do
241     let :facts do
242       {
243         :architecture    => 'amd64',
244         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
245         :lsbdistid       => 'Debian',
246         :lsbdistcodename => 'wheezy',
247         :osfamily        => 'Debian',
248         :puppetversion   => Puppet.version,
249       }
250     end
251     let :params do
252       {
253         :location => 'hello.there',
254         :include  => {'deb' => false, 'src' => true,},
255       }
256     end
257
258     it { is_expected.to contain_apt__setting('list-my_source').with({
259       :ensure => 'present',
260     }).with_content(/# my_source\ndeb-src hello.there wheezy main\n/)
261     }
262   end
263
264   context 'include_src => true' do
265     let :facts do
266       {
267         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
268         :lsbdistid       => 'Debian',
269         :lsbdistcodename => 'wheezy',
270         :osfamily        => 'Debian',
271         :puppetversion   => Puppet.version,
272       }
273     end
274     let :params do
275       {
276         :location    => 'hello.there',
277         :include     => {'src' => true},
278       }
279     end
280
281     it { is_expected.to contain_apt__setting('list-my_source').with({
282       :ensure => 'present',
283     }).with_content(/# my_source\ndeb hello.there wheezy main\ndeb-src hello.there wheezy main\n/)
284     }
285   end
286
287   context 'include deb => false' do
288     let :facts do
289       {
290         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
291         :lsbdistid       => 'debian',
292         :lsbdistcodename => 'wheezy',
293         :osfamily        => 'debian',
294         :puppetversion   => Puppet.version,
295       }
296     end
297     let :params do
298       {
299         :include => { 'deb' => false },
300         :location    => 'hello.there',
301       }
302     end
303
304     it { is_expected.to contain_apt__setting('list-my_source').with({
305       :ensure => 'present',
306     }).without_content(/deb-src hello.there wheezy main\n/)
307     }
308     it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
309   end
310
311   context 'include src => true and include deb => false' do
312     let :facts do
313       {
314         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
315         :lsbdistid       => 'debian',
316         :lsbdistcodename => 'wheezy',
317         :osfamily        => 'debian',
318         :puppetversion   => Puppet.version,
319       }
320     end
321     let :params do
322       {
323         :include => { 'deb' => false, 'src' => true },
324         :location    => 'hello.there',
325       }
326     end
327
328     it { is_expected.to contain_apt__setting('list-my_source').with({
329       :ensure => 'present',
330     }).with_content(/deb-src hello.there wheezy main\n/)
331     }
332     it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
333   end
334
335   context 'ensure => absent' do
336     let :facts do
337       {
338         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
339         :lsbdistid       => 'Debian',
340         :lsbdistcodename => 'wheezy',
341         :osfamily        => 'Debian',
342         :puppetversion   => Puppet.version,
343       }
344     end
345     let :params do
346       {
347         :ensure => 'absent',
348       }
349     end
350
351     it { is_expected.to contain_apt__setting('list-my_source').with({
352       :ensure => 'absent'
353     })
354     }
355   end
356
357   describe 'validation' do
358     context 'no release' do
359       let :facts do
360         {
361           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
362           :lsbdistid       => 'Debian',
363           :osfamily        => 'Debian',
364           :puppetversion   => Puppet.version,
365         }
366       end
367       let(:params) { { :location => 'hello.there', } }
368
369       it do
370         expect {
371           subject.call
372         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
373       end
374     end
375
376     context 'release is empty string' do
377       let :facts do
378         {
379           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
380           :lsbdistid       => 'Debian',
381           :osfamily        => 'Debian',
382           :puppetversion   => Puppet.version,
383         }
384       end
385       let(:params) { { :location => 'hello.there', :release => '' } }
386
387       it { is_expected.to contain_apt__setting('list-my_source').with_content(/hello\.there  main/) }
388     end
389
390     context 'invalid pin' do
391       let :facts do
392         {
393           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
394           :lsbdistid       => 'Debian',
395           :lsbdistcodename => 'wheezy',
396           :osfamily        => 'Debian',
397           :puppetversion   => Puppet.version,
398         }
399       end
400       let :params do
401         {
402           :location => 'hello.there',
403           :pin      => true,
404         }
405       end
406
407       it do
408         expect {
409           subject.call
410         }.to raise_error(Puppet::Error, /invalid value for pin/)
411       end
412     end
413
414     context "with notify_update = undef (default)" do
415       let :facts do
416         {
417           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
418           :lsbdistid       => 'Debian',
419           :lsbdistcodename => 'wheezy',
420           :osfamily        => 'Debian',
421           :puppetversion   => Puppet.version,
422         }
423       end
424       let :params do
425         {
426           :location      => 'hello.there',
427         }
428       end
429       it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
430     end
431
432     context "with notify_update = true" do
433       let :facts do
434         {
435           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
436           :lsbdistid       => 'Debian',
437           :lsbdistcodename => 'wheezy',
438           :osfamily        => 'Debian',
439           :puppetversion   => Puppet.version,
440         }
441       end
442       let :params do
443         {
444           :location      => 'hello.there',
445           :notify_update => true,
446         }
447       end
448       it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
449     end
450
451     context "with notify_update = false" do
452       let :facts do
453         {
454           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
455           :lsbdistid       => 'Debian',
456           :lsbdistcodename => 'wheezy',
457           :osfamily        => 'Debian',
458           :puppetversion   => Puppet.version,
459         }
460       end
461       let :params do
462         {
463           :location      => 'hello.there',
464           :notify_update => false,
465         }
466       end
467       it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }
468     end
469
470   end
471 end