Addressing Rubocop Errors
[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 'with 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 'with 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 'with everything set' 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 'when 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 'with all the needed things set' 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 'with 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         is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
143       end
144     end
145     context 'with missing release' do
146       let(:params) do
147         {
148           location: 'http://archive.ubuntu.com/ubuntu',
149           repos: 'main universe multiverse restricted',
150           key: '630239CC130E1A7FD81A27B140976EAF437D05B5',
151         }
152       end
153
154       it do
155         is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
156       end
157     end
158     context 'with missing repos' do
159       let(:params) do
160         {
161           location: 'http://archive.ubuntu.com/ubuntu',
162           release: 'trusty-backports',
163           key: '630239CC130E1A7FD81A27B140976EAF437D05B5',
164         }
165       end
166
167       it do
168         is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
169       end
170     end
171     context 'with missing key' do
172       let(:params) do
173         {
174           location: 'http://archive.ubuntu.com/ubuntu',
175           release: 'trusty-backports',
176           repos: 'main universe multiverse restricted',
177         }
178       end
179
180       it do
181         is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
182       end
183     end
184   end
185   describe 'validation' do
186     let(:facts) do
187       {
188         os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
189         lsbdistid: 'Ubuntu',
190         osfamily: 'Debian',
191         lsbdistcodename: 'trusty',
192         lsbdistrelease: '14.04',
193         puppetversion: Puppet.version,
194       }
195     end
196
197     context 'with invalid location' do
198       let(:params) do
199         {
200           location: true,
201         }
202       end
203
204       it do
205         is_expected.to raise_error(Puppet::Error, %r{expects a})
206       end
207     end
208     context 'with invalid release' do
209       let(:params) do
210         {
211           release: true,
212         }
213       end
214
215       it do
216         is_expected.to raise_error(Puppet::Error, %r{expects a})
217       end
218     end
219     context 'with invalid repos' do
220       let(:params) do
221         {
222           repos: true,
223         }
224       end
225
226       it do
227         is_expected.to raise_error(Puppet::Error, %r{expects a})
228       end
229     end
230     context 'with invalid key' do
231       let(:params) do
232         {
233           key: true,
234         }
235       end
236
237       it do
238         is_expected.to raise_error(Puppet::Error, %r{expects a})
239       end
240     end
241     context 'with invalid pin' do
242       let(:params) do
243         {
244           pin: true,
245         }
246       end
247
248       it do
249         is_expected.to raise_error(Puppet::Error, %r{expects a})
250       end
251     end
252   end
253 end