Puppet 4 language update
[puppet-modules/puppetlabs-apt.git] / spec / classes / apt_backports_spec.rb
1 #!/usr/bin/env rspec
2 require 'spec_helper'
3
4 describe 'apt::backports', :type => :class do
5   let (:pre_condition) { "class{ '::apt': }" }
6   describe 'debian/ubuntu tests' do
7     context '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       it { is_expected.to contain_apt__source('backports').with({
18         :location => 'http://httpredir.debian.org/debian',
19         :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
20         :repos    => 'main contrib non-free',
21         :release  => 'wheezy-backports',
22         :pin      => { 'priority' => 200, 'release' => 'wheezy-backports' },
23       })
24       }
25     end
26     context 'defaults on squeeze' do
27       let(:facts) do
28         {
29           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '6', :full => '6.0' }},
30           :lsbdistid       => 'Debian',
31           :osfamily        => 'Debian',
32           :lsbdistcodename => 'squeeze',
33           :puppetversion   => Puppet.version,
34         }
35       end
36       it { is_expected.to contain_apt__source('backports').with({
37         :location => 'http://httpredir.debian.org/debian-backports',
38         :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
39         :repos    => 'main contrib non-free',
40         :release  => 'squeeze-backports',
41         :pin      => { 'priority' => 200, 'release' => 'squeeze-backports' },
42       })
43       }
44     end
45     context 'defaults on ubuntu' do
46       let(:facts) do
47         {
48           :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
49           :lsbdistid       => 'Ubuntu',
50           :osfamily        => 'Debian',
51           :lsbdistcodename => 'trusty',
52           :lsbdistrelease  => '14.04',
53           :puppetversion   => Puppet.version,
54         }
55       end
56       it { is_expected.to contain_apt__source('backports').with({
57         :location => 'http://archive.ubuntu.com/ubuntu',
58         :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
59         :repos    => 'main universe multiverse restricted',
60         :release  => 'trusty-backports',
61         :pin      => { 'priority' => 200, 'release' => 'trusty-backports' },
62       })
63       }
64     end
65     context 'set everything' do
66       let(:facts) do
67         {
68           :lsbdistid       => 'Ubuntu',
69           :osfamily        => 'Debian',
70           :lsbdistcodename => 'trusty',
71           :lsbdistrelease  => '14.04',
72           :puppetversion   => Puppet.version,
73         }
74       end
75       let(:params) do
76         {
77           :location => 'http://archive.ubuntu.com/ubuntu-test',
78           :release  => 'vivid',
79           :repos    => 'main',
80           :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
81           :pin      => '90',
82         }
83       end
84       it { is_expected.to contain_apt__source('backports').with({
85         :location => 'http://archive.ubuntu.com/ubuntu-test',
86         :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
87         :repos    => 'main',
88         :release  => 'vivid',
89         :pin      => { 'priority' => 90, 'release' => 'vivid' },
90       })
91       }
92     end
93     context 'set things with hashes' do
94       let(:facts) do
95         {
96           :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
97           :lsbdistid       => 'Ubuntu',
98           :osfamily        => 'Debian',
99           :lsbdistcodename => 'trusty',
100           :lsbdistrelease  => '14.04',
101           :puppetversion   => Puppet.version,
102         }
103       end
104       let(:params) do
105         {
106           :key => {
107             'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
108           },
109           :pin => {
110             'priority' => '90',
111           },
112         }
113       end
114       it { is_expected.to contain_apt__source('backports').with({
115         :key      => { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
116         :pin      => { 'priority' => '90' },
117       })
118       }
119     end
120   end
121   describe 'mint tests' do
122     let(:facts) do
123       {
124         :lsbdistid       => 'linuxmint',
125         :osfamily        => 'Debian',
126         :lsbdistcodename => 'qiana',
127         :puppetversion   => Puppet.version,
128       }
129     end
130     context 'sets all the needed things' do
131       let(:params) do
132         {
133           :location => 'http://archive.ubuntu.com/ubuntu',
134           :release  => 'trusty-backports',
135           :repos    => 'main universe multiverse restricted',
136           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
137         }
138       end
139       it { is_expected.to contain_apt__source('backports').with({
140         :location => 'http://archive.ubuntu.com/ubuntu',
141         :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
142         :repos    => 'main universe multiverse restricted',
143         :release  => 'trusty-backports',
144         :pin      => { 'priority' => 200, 'release' => 'trusty-backports' },
145       })
146       }
147     end
148     context 'missing location' do
149       let(:params) do
150         {
151           :release  => 'trusty-backports',
152           :repos    => 'main universe multiverse restricted',
153           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
154         }
155       end
156       it do
157         expect {
158           subject.call
159         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
160       end
161     end
162     context 'missing release' do
163       let(:params) do
164         {
165           :location => 'http://archive.ubuntu.com/ubuntu',
166           :repos    => 'main universe multiverse restricted',
167           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
168         }
169       end
170       it do
171         expect {
172           subject.call
173         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
174       end
175     end
176     context 'missing repos' do
177       let(:params) do
178         {
179           :location => 'http://archive.ubuntu.com/ubuntu',
180           :release  => 'trusty-backports',
181           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
182         }
183       end
184       it do
185         expect {
186           subject.call
187         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
188       end
189     end
190     context 'missing key' do
191       let(:params) do
192         {
193           :location => 'http://archive.ubuntu.com/ubuntu',
194           :release  => 'trusty-backports',
195           :repos    => 'main universe multiverse restricted',
196         }
197       end
198       it do
199         expect {
200           subject.call
201         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
202       end
203     end
204   end
205   describe 'validation' do
206     let(:facts) do
207       {
208         :lsbdistid       => 'Ubuntu',
209         :osfamily        => 'Debian',
210         :lsbdistcodename => 'trusty',
211         :lsbdistrelease  => '14.04',
212         :puppetversion   => Puppet.version,
213       }
214     end
215     context 'invalid location' do
216       let(:params) do
217         {
218           :location => true
219         }
220       end
221       it do
222         expect {
223           subject.call
224         }.to raise_error(Puppet::Error, /expects a String value/)
225       end
226     end
227     context 'invalid release' do
228       let(:params) do
229         {
230           :release => true
231         }
232       end
233       it do
234         expect {
235           subject.call
236         }.to raise_error(Puppet::Error, /expects a String value/)
237       end
238     end
239     context 'invalid repos' do
240       let(:params) do
241         {
242           :repos => true
243         }
244       end
245       it do
246         expect {
247           subject.call
248         }.to raise_error(Puppet::Error, /expects a String value/)
249       end
250     end
251     context 'invalid key' do
252       let(:params) do
253         {
254           :key => true
255         }
256       end
257       it do
258         expect {
259           subject.call
260         }.to raise_error(Puppet::Error, /expects a value of type String, Hash,/)
261       end
262     end
263     context 'invalid pin' do
264       let(:params) do
265         {
266           :pin => true
267         }
268       end
269       it do
270         expect {
271           subject.call
272         }.to raise_error(Puppet::Error, /parameter 'pin' expects a value of type Integer, Pattern/)
273       end
274     end
275   end
276 end