Merge pull request #323 from cmurphy/master
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / pin_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'apt::pin define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4   context 'defaults' do
5     it 'should work with no errors' do
6       pp = <<-EOS
7       include apt
8       apt::pin { 'vim-puppet': }
9       EOS
10
11       apply_manifest(pp, :catch_failures => true)
12     end
13
14     describe file('/etc/apt/preferences.d/vim-puppet.pref') do
15       it { should be_file }
16       it { should contain 'Pin: release a=vim-puppet' }
17     end
18   end
19
20   context 'ensure' do
21     context 'present' do
22       it 'should work with no errors' do
23         pp = <<-EOS
24         include apt
25         apt::pin { 'vim-puppet': ensure => present }
26         EOS
27
28         apply_manifest(pp, :catch_failures => true)
29       end
30
31       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
32         it { should be_file }
33         it { should contain 'Pin: release a=vim-puppet' }
34       end
35     end
36
37     context 'absent' do
38       it 'should work with no errors' do
39         pp = <<-EOS
40         include apt
41         apt::pin { 'vim-puppet': ensure => absent }
42         EOS
43
44         apply_manifest(pp, :catch_failures => true)
45       end
46
47       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
48         it { should_not be_file }
49       end
50     end
51   end
52
53   context 'order' do
54     context '99' do
55       it 'should work with no errors' do
56         pp = <<-EOS
57         include apt
58         apt::pin { 'vim-puppet':
59           ensure => present,
60           order  => '99',
61         }
62         EOS
63
64         apply_manifest(pp, :catch_failures => true)
65       end
66
67       describe file('/etc/apt/preferences.d/99-vim-puppet.pref') do
68         it { should be_file }
69         it { should contain 'Pin: release a=vim-puppet' }
70       end
71     end
72   end
73
74   context 'packages' do
75     context 'test' do
76       it 'should work with no errors' do
77         pp = <<-EOS
78         include apt
79         apt::pin { 'vim-puppet':
80           ensure   => present,
81           packages => 'test',
82         }
83         EOS
84
85         apply_manifest(pp, :catch_failures => true)
86       end
87
88       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
89         it { should be_file }
90         it { should contain 'Package: test' }
91         it { should contain 'Pin: release a=vim-puppet' }
92       end
93     end
94
95     context 'array' do
96       it 'should work with no errors' do
97         pp = <<-EOS
98         include apt
99         apt::pin { 'array':
100           ensure   => present,
101           packages => ['apache', 'ntop'],
102         }
103         EOS
104
105         apply_manifest(pp, :catch_failures => true)
106       end
107
108       describe file('/etc/apt/preferences.d/array.pref') do
109         it { should be_file }
110         it { should contain 'Package: apache ntop' }
111         it { should contain 'Pin: release a=array' }
112       end
113     end
114   end
115
116   context 'release' do
117     context 'testrelease' do
118       it 'should work with no errors' do
119         pp = <<-EOS
120         include apt
121         apt::pin { 'vim-puppet':
122           ensure  => present,
123           release => 'testrelease',
124         }
125         EOS
126
127         apply_manifest(pp, :catch_failures => true)
128       end
129
130       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
131         it { should be_file }
132         it { should contain 'Pin: release a=testrelease' }
133       end
134     end
135   end
136
137   context 'origin' do
138     context 'testrelease' do
139       it 'should work with no errors' do
140         pp = <<-EOS
141         include apt
142         apt::pin { 'vim-puppet':
143           ensure  => present,
144           origin  => 'testrelease',
145         }
146         EOS
147
148         apply_manifest(pp, :catch_failures => true)
149       end
150
151       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
152         it { should be_file }
153         it { should contain 'Pin: origin testrelease' }
154       end
155     end
156   end
157
158   context 'version' do
159     context '1.0.0' do
160       it 'should work with no errors' do
161         pp = <<-EOS
162         include apt
163         apt::pin { 'vim-puppet':
164           ensure   => present,
165           packages => 'test',
166           version  => '1.0.0',
167         }
168         EOS
169
170         apply_manifest(pp, :catch_failures => true)
171       end
172
173       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
174         it { should be_file }
175         it { should contain 'Package: test' }
176         it { should contain 'Pin: version 1.0.0' }
177       end
178     end
179   end
180
181   context 'codename' do
182     context 'testname' do
183       it 'should work with no errors' do
184         pp = <<-EOS
185         include apt
186         apt::pin { 'vim-puppet':
187           ensure   => present,
188           codename => 'testname',
189         }
190         EOS
191
192         apply_manifest(pp, :catch_failures => true)
193       end
194
195       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
196         it { should be_file }
197         it { should contain 'Pin: release n=testname' }
198       end
199     end
200   end
201
202   context 'release_version' do
203     context '1.1.1' do
204       it 'should work with no errors' do
205         pp = <<-EOS
206         include apt
207         apt::pin { 'vim-puppet':
208           ensure          => present,
209           release_version => '1.1.1',
210         }
211         EOS
212
213         apply_manifest(pp, :catch_failures => true)
214       end
215
216       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
217         it { should be_file }
218         it { should contain 'Pin: release v=1.1.1' }
219       end
220     end
221   end
222
223   context 'component' do
224     context 'testcomponent' do
225       it 'should work with no errors' do
226         pp = <<-EOS
227         include apt
228         apt::pin { 'vim-puppet':
229           ensure    => present,
230           component => 'testcomponent',
231         }
232         EOS
233
234         apply_manifest(pp, :catch_failures => true)
235       end
236
237       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
238         it { should be_file }
239         it { should contain 'Pin: release c=testcomponent' }
240       end
241     end
242   end
243
244   context 'originator' do
245     context 'testorigin' do
246       it 'should work with no errors' do
247         pp = <<-EOS
248         include apt
249         apt::pin { 'vim-puppet':
250           ensure     => present,
251           originator => 'testorigin',
252         }
253         EOS
254
255         apply_manifest(pp, :catch_failures => true)
256       end
257
258       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
259         it { should be_file }
260         it { should contain 'Pin: release o=testorigin' }
261       end
262     end
263   end
264
265   context 'label' do
266     context 'testlabel' do
267       it 'should work with no errors' do
268         pp = <<-EOS
269         include apt
270         apt::pin { 'vim-puppet':
271           ensure => present,
272           label  => 'testlabel',
273         }
274         EOS
275
276         apply_manifest(pp, :catch_failures => true)
277       end
278
279       describe file('/etc/apt/preferences.d/vim-puppet.pref') do
280         it { should be_file }
281         it { should contain 'Pin: release l=testlabel' }
282       end
283     end
284   end
285
286 end