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