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