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