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