Merge pull request #239 from hunner/fix_builddep
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / apt_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'apt class' do
4
5   context 'reset' do
6     it 'fixes the sources.list' do
7       shell('cp /etc/apt/sources.list /tmp')
8     end
9   end
10
11   context 'always_apt_update => true' do
12     it 'should work with no errors' do
13       pp = <<-EOS
14       class { 'apt': always_apt_update => true }
15       EOS
16
17       apply_manifest(pp, :catch_failures => true) do |r|
18         expect(r.stdout).to match(/apt_update/)
19       end
20     end
21   end
22   context 'always_apt_update => false' do
23     it 'should work with no errors' do
24       pp = <<-EOS
25       class { 'apt': always_apt_update => false }
26       EOS
27
28       apply_manifest(pp, :catch_failures => true) do |r|
29         expect(r.stdout).to_not match(/apt_update/)
30       end
31     end
32   end
33
34   # disable_keys drops in a 99unauth file to ignore keys in
35   # other files.
36   context 'disable_keys => true' do
37     it 'should work with no errors' do
38       pp = <<-EOS
39       class { 'apt': disable_keys => true }
40       EOS
41
42       apply_manifest(pp, :catch_failures => true)
43     end
44
45     describe file('/etc/apt/apt.conf.d/99unauth') do
46       it { should be_file }
47       it { should contain 'APT::Get::AllowUnauthenticated 1;' }
48     end
49   end
50   context 'disable_keys => false' do
51     it 'should work with no errors' do
52       pp = <<-EOS
53       class { 'apt': disable_keys => false }
54       EOS
55
56       apply_manifest(pp, :catch_failures => true)
57     end
58
59     describe file('/etc/apt/apt.conf.d/99unauth') do
60       it { should_not be_file }
61     end
62   end
63
64   # proxy_host sets the proxy to use for transfers.
65   # proxy_port sets the proxy port to use.
66   context 'proxy settings' do
67     it 'should work with no errors' do
68       pp = <<-EOS
69       class { 'apt': 
70         proxy_host => 'localhost',
71         proxy_port => '7042',
72       }
73       EOS
74
75       apply_manifest(pp, :catch_failures => true)
76     end
77
78     describe file('/etc/apt/apt.conf.d/proxy') do
79       it { should be_file }
80       it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
81     end
82   end
83
84   context 'purge_sources' do
85     it 'creates a fake apt file' do
86       shell('touch /etc/apt/sources.list.d/fake.list')
87       shell('echo "deb fake" >> /etc/apt/sources.list')
88     end
89     it 'purge_sources_list and purge_sources_list_d => true' do
90       pp = <<-EOS
91       class { 'apt':
92         purge_sources_list   => true,
93         purge_sources_list_d => true,
94       }
95       EOS
96
97       apply_manifest(pp, :catch_failures => true)
98     end
99
100     describe file('/etc/apt/sources.list') do
101       it { should_not contain 'deb fake' }
102     end
103
104     describe file('/etc/apt/sources.list.d/fake.list') do
105       it { should_not be_file }
106     end
107   end
108   context 'proxy settings' do
109     it 'should work with no errors' do
110       pp = <<-EOS
111       class { 'apt': 
112         proxy_host => 'localhost',
113         proxy_port => '7042',
114       }
115       EOS
116
117       apply_manifest(pp, :catch_failures => true)
118     end
119
120     describe file('/etc/apt/apt.conf.d/proxy') do
121       it { should be_file }
122       it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
123     end
124   end
125
126   context 'purge_sources' do
127     context 'false' do
128       it 'creates a fake apt file' do
129         shell('touch /etc/apt/sources.list.d/fake.list')
130         shell('echo "deb fake" >> /etc/apt/sources.list')
131       end
132       it 'purge_sources_list and purge_sources_list_d => false' do
133         pp = <<-EOS
134         class { 'apt':
135           purge_sources_list   => false,
136           purge_sources_list_d => false,
137         }
138         EOS
139
140         apply_manifest(pp, :catch_failures => false)
141       end
142
143       describe file('/etc/apt/sources.list') do
144         it { should contain 'deb fake' }
145       end
146
147       describe file('/etc/apt/sources.list.d/fake.list') do
148         it { should be_file }
149       end
150     end
151
152     context 'true' do
153       it 'creates a fake apt file' do
154         shell('touch /etc/apt/sources.list.d/fake.list')
155         shell('echo "deb fake" >> /etc/apt/sources.list')
156       end
157       it 'purge_sources_list and purge_sources_list_d => true' do
158         pp = <<-EOS
159         class { 'apt':
160           purge_sources_list   => true,
161           purge_sources_list_d => true,
162         }
163         EOS
164
165         apply_manifest(pp, :catch_failures => true)
166       end
167
168       describe file('/etc/apt/sources.list') do
169         it { should_not contain 'deb fake' }
170       end
171
172       describe file('/etc/apt/sources.list.d/fake.list') do
173         it { should_not be_file }
174       end
175     end
176   end
177
178   context 'purge_preferences_d' do
179     context 'false' do
180       it 'creates a preferences file' do
181         shell('touch /etc/apt/preferences.d/test')
182       end
183
184       it 'should work with no errors' do
185         pp = <<-EOS
186         class { 'apt': purge_preferences_d => false }
187         EOS
188
189         apply_manifest(pp, :catch_failures => true)
190       end
191
192       describe file('/etc/apt/preferences.d/test') do
193         it { should be_file }
194       end
195     end
196     context 'true' do
197       it 'creates a preferences file' do
198         shell('touch /etc/apt/preferences.d/test')
199       end
200
201       it 'should work with no errors' do
202         pp = <<-EOS
203         class { 'apt': purge_preferences_d => true }
204         EOS
205
206         apply_manifest(pp, :catch_failures => true)
207       end
208
209       describe file('/etc/apt/preferences.d/test') do
210         it { should_not be_file }
211       end
212     end
213   end
214
215   context 'update_timeout' do
216     context '5000' do
217       it 'should work with no errors' do
218         pp = <<-EOS
219         class { 'apt': update_timeout => '5000' }
220         EOS
221
222         apply_manifest(pp, :catch_failures => true)
223       end
224     end
225   end
226
227   context 'reset' do
228     it 'fixes the sources.list' do
229       shell('cp /tmp/sources.list /etc/apt')
230     end
231   end
232
233 end