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