f2172d92a99396031c349062a70725e4eed2cbea
[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://deb.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 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       it { is_expected.to contain_apt__source('backports').with({
38         :location => 'http://archive.ubuntu.com/ubuntu',
39         :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
40         :repos    => 'main universe multiverse restricted',
41         :release  => 'trusty-backports',
42         :pin      => { 'priority' => 200, 'release' => 'trusty-backports' },
43       })
44       }
45     end
46     context 'set everything' 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       it { is_expected.to contain_apt__source('backports').with({
67         :location => 'http://archive.ubuntu.com/ubuntu-test',
68         :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
69         :repos    => 'main',
70         :release  => 'vivid',
71         :pin      => { 'priority' => 90, 'release' => 'vivid' },
72       })
73       }
74     end
75     context '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       it { is_expected.to contain_apt__source('backports').with({
97         :key      => { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
98         :pin      => { 'priority' => '90' },
99       })
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     context 'sets all the needed things' do
114       let(:params) do
115         {
116           :location => 'http://archive.ubuntu.com/ubuntu',
117           :release  => 'trusty-backports',
118           :repos    => 'main universe multiverse restricted',
119           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
120         }
121       end
122       it { is_expected.to contain_apt__source('backports').with({
123         :location => 'http://archive.ubuntu.com/ubuntu',
124         :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
125         :repos    => 'main universe multiverse restricted',
126         :release  => 'trusty-backports',
127         :pin      => { 'priority' => 200, 'release' => 'trusty-backports' },
128       })
129       }
130     end
131     context 'missing location' do
132       let(:params) do
133         {
134           :release  => 'trusty-backports',
135           :repos    => 'main universe multiverse restricted',
136           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
137         }
138       end
139       it do
140         expect {
141           subject.call
142         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
143       end
144     end
145     context '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       it do
154         expect {
155           subject.call
156         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
157       end
158     end
159     context 'missing repos' do
160       let(:params) do
161         {
162           :location => 'http://archive.ubuntu.com/ubuntu',
163           :release  => 'trusty-backports',
164           :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
165         }
166       end
167       it do
168         expect {
169           subject.call
170         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
171       end
172     end
173     context 'missing key' do
174       let(:params) do
175         {
176           :location => 'http://archive.ubuntu.com/ubuntu',
177           :release  => 'trusty-backports',
178           :repos    => 'main universe multiverse restricted',
179         }
180       end
181       it do
182         expect {
183           subject.call
184         }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
185       end
186     end
187   end
188   describe 'validation' do
189     let(:facts) do
190       {
191         :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
192         :lsbdistid       => 'Ubuntu',
193         :osfamily        => 'Debian',
194         :lsbdistcodename => 'trusty',
195         :lsbdistrelease  => '14.04',
196         :puppetversion   => Puppet.version,
197       }
198     end
199     context 'invalid location' do
200       let(:params) do
201         {
202           :location => true
203         }
204       end
205       it do
206         expect {
207           subject.call
208         }.to raise_error(Puppet::Error, /expects a/)
209       end
210     end
211     context 'invalid release' do
212       let(:params) do
213         {
214           :release => true
215         }
216       end
217       it do
218         expect {
219           subject.call
220         }.to raise_error(Puppet::Error, /expects a/)
221       end
222     end
223     context 'invalid repos' do
224       let(:params) do
225         {
226           :repos => true
227         }
228       end
229       it do
230         expect {
231           subject.call
232         }.to raise_error(Puppet::Error, /expects a/)
233       end
234     end
235     context 'invalid key' do
236       let(:params) do
237         {
238           :key => true
239         }
240       end
241       it do
242         expect {
243           subject.call
244         }.to raise_error(Puppet::Error, /expects a/)
245       end
246     end
247     context 'invalid pin' do
248       let(:params) do
249         {
250           :pin => true
251         }
252       end
253       it do
254         expect {
255           subject.call
256         }.to raise_error(Puppet::Error, /expects a/)
257       end
258     end
259   end
260 end