Merge pull request #674 from hunner/fix_specs
[puppet-modules/puppetlabs-apt.git] / spec / classes / apt_backports_spec.rb
1 #!/usr/bin/env rspec
2 require 'spec_helper'
3
4 describe 'apt::backports', :type => :class do
5   let (:pre_condition) { "class{ '::apt': }" }
6   describe 'debian/ubuntu tests' do
7     context 'defaults on deb' do
8       let(:facts) do
9         {
10           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
11           :lsbdistid       => 'Debian',
12           :osfamily        => 'Debian',
13           :lsbdistcodename => 'wheezy',
14           :puppetversion   => Puppet.version,
15         }
16       end
17       it { is_expected.to contain_apt__source('backports').with({
18         :location => 'http://httpredir.debian.org/debian',
19         :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
20         :repos    => 'main contrib non-free',
21         :release  => 'wheezy-backports',
22         :pin      => { 'priority' => 200, 'release' => 'wheezy-backports' },
23       })
24       }
25     end
26     context 'defaults on squeeze' do
27       let(:facts) do
28         {
29           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '6', :full => '6.0' }},
30           :lsbdistid       => 'Debian',
31           :osfamily        => 'Debian',
32           :lsbdistcodename => 'squeeze',
33           :puppetversion   => Puppet.version,
34         }
35       end
36       it { is_expected.to contain_apt__source('backports').with({
37         :location => 'http://httpredir.debian.org/debian-backports',
38         :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
39         :repos    => 'main contrib non-free',
40         :release  => 'squeeze-backports',
41         :pin      => { 'priority' => 200, 'release' => 'squeeze-backports' },
42       })
43       }
44     end
45     context 'defaults on ubuntu' do
46       let(:facts) do
47         {
48           :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
49           :lsbdistid       => 'Ubuntu',
50           :osfamily        => 'Debian',
51           :lsbdistcodename => 'trusty',
52           :lsbdistrelease  => '14.04',
53           :puppetversion   => Puppet.version,
54         }
55       end
56       it { is_expected.to contain_apt__source('backports').with({
57         :location => 'http://archive.ubuntu.com/ubuntu',
58         :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
59         :repos    => 'main universe multiverse restricted',
60         :release  => 'trusty-backports',
61         :pin      => { 'priority' => 200, 'release' => 'trusty-backports' },
62       })
63       }
64     end
65     context 'set everything' do
66       let(:facts) do
67         {
68           :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
69           :lsbdistid       => 'Ubuntu',
70           :osfamily        => 'Debian',
71           :lsbdistcodename => 'trusty',
72           :lsbdistrelease  => '14.04',
73           :puppetversion   => Puppet.version,
74         }
75       end
76       let(:params) do
77         {
78           :location => 'http://archive.ubuntu.com/ubuntu-test',
79           :release  => 'vivid',
80           :repos    => 'main',
81           :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
82           :pin      => '90',
83         }
84       end
85       it { is_expected.to contain_apt__source('backports').with({
86         :location => 'http://archive.ubuntu.com/ubuntu-test',
87         :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
88         :repos    => 'main',
89         :release  => 'vivid',
90         :pin      => { 'priority' => 90, 'release' => 'vivid' },
91       })
92       }
93     end
94     context 'set things with hashes' do
95       let(:facts) do
96         {
97           :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
98           :lsbdistid       => 'Ubuntu',
99           :osfamily        => 'Debian',
100           :lsbdistcodename => 'trusty',
101           :lsbdistrelease  => '14.04',
102           :puppetversion   => Puppet.version,
103         }
104       end
105       let(:params) do
106         {
107           :key => {
108             'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
109           },
110           :pin => {
111             'priority' => '90',
112           },
113         }
114       end
115       it { is_expected.to contain_apt__source('backports').with({
116         :key      => { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
117         :pin      => { 'priority' => '90' },
118       })
119       }
120     end
121   end
122   describe 'mint tests' do
123     let(:facts) do
124       {
125         :os => { :family => 'Debian', :name => 'Linuxmint', :release => { :major => '17', :full => '17' }},
126         :lsbdistid       => 'linuxmint',
127         :osfamily        => 'Debian',
128         :lsbdistcodename => 'qiana',
129         :puppetversion   => Puppet.version,
130       }
131     end
132     context 'sets all the needed things' do
133       let(:params) do
134         {
135           :location => 'http://archive.ubuntu.com/ubuntu',
136           :release  => 'trusty-backports',
137           :repos    => 'main universe multiverse restricted',
138           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
139         }
140       end
141       it { is_expected.to contain_apt__source('backports').with({
142         :location => 'http://archive.ubuntu.com/ubuntu',
143         :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
144         :repos    => 'main universe multiverse restricted',
145         :release  => 'trusty-backports',
146         :pin      => { 'priority' => 200, 'release' => 'trusty-backports' },
147       })
148       }
149     end
150     context 'missing location' do
151       let(:params) do
152         {
153           :release  => 'trusty-backports',
154           :repos    => 'main universe multiverse restricted',
155           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
156         }
157       end
158       it do
159         expect {
160           subject.call
161         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
162       end
163     end
164     context 'missing release' do
165       let(:params) do
166         {
167           :location => 'http://archive.ubuntu.com/ubuntu',
168           :repos    => 'main universe multiverse restricted',
169           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
170         }
171       end
172       it do
173         expect {
174           subject.call
175         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
176       end
177     end
178     context 'missing repos' do
179       let(:params) do
180         {
181           :location => 'http://archive.ubuntu.com/ubuntu',
182           :release  => 'trusty-backports',
183           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
184         }
185       end
186       it do
187         expect {
188           subject.call
189         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
190       end
191     end
192     context 'missing key' do
193       let(:params) do
194         {
195           :location => 'http://archive.ubuntu.com/ubuntu',
196           :release  => 'trusty-backports',
197           :repos    => 'main universe multiverse restricted',
198         }
199       end
200       it do
201         expect {
202           subject.call
203         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
204       end
205     end
206   end
207   describe 'validation' do
208     let(:facts) do
209       {
210         :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
211         :lsbdistid       => 'Ubuntu',
212         :osfamily        => 'Debian',
213         :lsbdistcodename => 'trusty',
214         :lsbdistrelease  => '14.04',
215         :puppetversion   => Puppet.version,
216       }
217     end
218     context 'invalid location' do
219       let(:params) do
220         {
221           :location => true
222         }
223       end
224       it do
225         expect {
226           subject.call
227         }.to raise_error(Puppet::Error, /expects a/)
228       end
229     end
230     context 'invalid release' do
231       let(:params) do
232         {
233           :release => true
234         }
235       end
236       it do
237         expect {
238           subject.call
239         }.to raise_error(Puppet::Error, /expects a/)
240       end
241     end
242     context 'invalid repos' do
243       let(:params) do
244         {
245           :repos => true
246         }
247       end
248       it do
249         expect {
250           subject.call
251         }.to raise_error(Puppet::Error, /expects a/)
252       end
253     end
254     context 'invalid key' do
255       let(:params) do
256         {
257           :key => true
258         }
259       end
260       it do
261         expect {
262           subject.call
263         }.to raise_error(Puppet::Error, /expects a/)
264       end
265     end
266     context 'invalid pin' do
267       let(:params) do
268         {
269           :pin => true
270         }
271       end
272       it do
273         expect {
274           subject.call
275         }.to raise_error(Puppet::Error, /expects a/)
276       end
277     end
278   end
279 end