]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/blob - spec/defines/source_spec.rb
Fix architecture fact overriding unset `architecture` source option
[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         :location    => 'hello.there',
300         :include_deb => false,
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         :location    => 'hello.there',
324         :include_deb => false,
325         :include_src => true,
326       }
327     end
328
329     it { is_expected.to contain_apt__setting('list-my_source').with({
330       :ensure => 'present',
331     }).with_content(/deb-src hello.there wheezy main\n/)
332     }
333     it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
334   end
335
336   context 'include precedence' do
337     let :facts do
338       {
339         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
340         :lsbdistid       => 'debian',
341         :lsbdistcodename => 'wheezy',
342         :osfamily        => 'debian',
343         :puppetversion   => Puppet.version,
344       }
345     end
346     let :params do
347       {
348         :location    => 'hello.there',
349         :include_deb => true,
350         :include_src => false,
351         :include     => { 'deb' => false, 'src' => true },
352       }
353     end
354
355     it { is_expected.to contain_apt__setting('list-my_source').with({
356       :ensure => 'present',
357     }).with_content(/deb-src hello.there wheezy main\n/)
358     }
359     it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
360   end
361
362   context 'ensure => absent' do
363     let :facts do
364       {
365         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
366         :lsbdistid       => 'Debian',
367         :lsbdistcodename => 'wheezy',
368         :osfamily        => 'Debian',
369         :puppetversion   => Puppet.version,
370       }
371     end
372     let :params do
373       {
374         :ensure => 'absent',
375       }
376     end
377
378     it { is_expected.to contain_apt__setting('list-my_source').with({
379       :ensure => 'absent'
380     })
381     }
382   end
383
384   describe 'validation' do
385     context 'no release' do
386       let :facts do
387         {
388           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
389           :lsbdistid       => 'Debian',
390           :osfamily        => 'Debian',
391           :puppetversion   => Puppet.version,
392         }
393       end
394       let(:params) { { :location => 'hello.there', } }
395
396       it do
397         expect {
398           subject.call
399         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
400       end
401     end
402
403     context 'invalid pin' do
404       let :facts do
405         {
406           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
407           :lsbdistid       => 'Debian',
408           :lsbdistcodename => 'wheezy',
409           :osfamily        => 'Debian',
410           :puppetversion   => Puppet.version,
411         }
412       end
413       let :params do
414         {
415           :location => 'hello.there',
416           :pin      => true,
417         }
418       end
419
420       it do
421         expect {
422           subject.call
423         }.to raise_error(Puppet::Error, /invalid value for pin/)
424       end
425     end
426
427     context "with notify_update = undef (default)" do
428       let :facts do
429         {
430           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
431           :lsbdistid       => 'Debian',
432           :lsbdistcodename => 'wheezy',
433           :osfamily        => 'Debian',
434           :puppetversion   => Puppet.version,
435         }
436       end
437       let :params do
438         {
439           :location      => 'hello.there',
440         }
441       end
442       it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
443     end
444
445     context "with notify_update = true" do
446       let :facts do
447         {
448           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
449           :lsbdistid       => 'Debian',
450           :lsbdistcodename => 'wheezy',
451           :osfamily        => 'Debian',
452           :puppetversion   => Puppet.version,
453         }
454       end
455       let :params do
456         {
457           :location      => 'hello.there',
458           :notify_update => true,
459         }
460       end
461       it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
462     end
463
464     context "with notify_update = false" do
465       let :facts do
466         {
467           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
468           :lsbdistid       => 'Debian',
469           :lsbdistcodename => 'wheezy',
470           :osfamily        => 'Debian',
471           :puppetversion   => Puppet.version,
472         }
473       end
474       let :params do
475         {
476           :location      => 'hello.there',
477           :notify_update => false,
478         }
479       end
480       it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }
481     end
482
483   end
484 end