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