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