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