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