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