Merge pull request #588 from werekraken/modules2873
[puppet-modules/puppetlabs-apt.git] / spec / defines / ppa_spec.rb
1 require 'spec_helper'
2 describe 'apt::ppa' do
3   let :pre_condition do
4     'class { "apt": }'
5   end
6
7   describe 'defaults' do
8     let :facts do
9       {
10         :lsbdistrelease  => '11.04',
11         :lsbdistcodename => 'natty',
12         :operatingsystem => 'Ubuntu',
13         :osfamily        => 'Debian',
14         :lsbdistid       => 'Ubuntu',
15         :puppetversion   => Puppet.version,
16       }
17     end
18
19     let(:title) { 'ppa:needs/such.substitution/wow+type' }
20     it { is_expected.to_not contain_package('python-software-properties') }
21     it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow+type').that_notifies('Class[Apt::Update]').with({
22       :environment => [],
23       :command     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type',
24       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow_type-natty.list',
25       :user        => 'root',
26       :logoutput   => 'on_failure',
27     })
28     }
29   end
30
31   describe 'ppa depending on ppa, MODULES-1156' do
32     let :pre_condition do
33       'class { "apt": }'
34     end
35   end
36
37   describe 'package_name => software-properties-common' do
38     let :pre_condition do
39       'class { "apt": }'
40     end
41     let :params do
42       {
43         :package_name   => 'software-properties-common',
44         :package_manage => true,
45       }
46     end
47     let :facts do
48       {
49         :lsbdistrelease  => '11.04',
50         :lsbdistcodename => 'natty',
51         :operatingsystem => 'Ubuntu',
52         :osfamily        => 'Debian',
53         :lsbdistid       => 'Ubuntu',
54         :puppetversion   => Puppet.version,
55       }
56     end
57
58     let(:title) { 'ppa:needs/such.substitution/wow' }
59     it { is_expected.to contain_package('software-properties-common') }
60     it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with({
61       'environment' => [],
62       'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
63       'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
64       'user'        => 'root',
65       'logoutput'   => 'on_failure',
66     })
67     }
68
69     it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({
70       'ensure' => 'file',
71     })
72     }
73   end
74
75   describe 'package_manage => true, multiple ppas, MODULES-2873' do
76     let :pre_condition do
77       'class { "apt": }
78        apt::ppa {"ppa:foo":
79          package_manage => true
80        }'
81     end
82     let :facts do
83       {
84         :lsbdistrelease  => '11.04',
85         :lsbdistcodename => 'natty',
86         :operatingsystem => 'Ubuntu',
87         :osfamily        => 'Debian',
88         :lsbdistid       => 'Ubuntu',
89         :puppetversion   => Puppet.version,
90       }
91     end
92     let :params do
93       {
94         :package_manage => true,
95       }
96     end
97
98     let(:title) { 'ppa:bar' }
99     it { is_expected.to contain_package('python-software-properties') }
100     it { is_expected.to contain_exec('add-apt-repository-ppa:bar').that_notifies('Class[Apt::Update]').with({
101       'environment' => [],
102       'command'     => '/usr/bin/add-apt-repository -y ppa:bar',
103       'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/bar-natty.list',
104       'user'        => 'root',
105       'logoutput'   => 'on_failure',
106     })
107     }
108
109     it { is_expected.to contain_file('/etc/apt/sources.list.d/bar-natty.list').that_requires('Exec[add-apt-repository-ppa:bar]').with({
110       'ensure' => 'file',
111     })
112     }
113   end
114
115   describe 'package_manage => false' do
116     let :pre_condition do
117       'class { "apt": }'
118     end
119     let :facts do
120       {
121         :lsbdistrelease  => '11.04',
122         :lsbdistcodename => 'natty',
123         :operatingsystem => 'Ubuntu',
124         :osfamily        => 'Debian',
125         :lsbdistid       => 'Ubuntu',
126         :puppetversion   => Puppet.version,
127       }
128     end
129     let :params do
130       {
131         :package_manage => false,
132       }
133     end
134
135     let(:title) { 'ppa:needs/such.substitution/wow' }
136     it { is_expected.to_not contain_package('python-software-properties') }
137     it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with({
138       'environment' => [],
139       'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
140       'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
141       'user'        => 'root',
142       'logoutput'   => 'on_failure',
143     })
144     }
145
146     it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({
147       'ensure' => 'file',
148     })
149     }
150   end
151
152   describe 'apt included, no proxy' do
153     let :pre_condition do
154       'class { "apt": }
155       apt::ppa { "ppa:foo2": }
156       '
157     end
158     let :facts do
159       {
160         :lsbdistrelease  => '14.04',
161         :lsbdistcodename => 'trusty',
162         :operatingsystem => 'Ubuntu',
163         :lsbdistid       => 'Ubuntu',
164         :osfamily        => 'Debian',
165         :puppetversion   => Puppet.version,
166       }
167     end
168     let :params do
169       {
170         :options        => '',
171         :package_manage => true,
172         :require        => 'Apt::Ppa[ppa:foo2]',
173       }
174     end
175     let(:title) { 'ppa:foo' }
176     it { is_expected.to compile.with_all_deps }
177     it { is_expected.to contain_package('software-properties-common') }
178     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
179       :environment => [],
180       :command     => '/usr/bin/add-apt-repository  ppa:foo',
181       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
182       :user        => 'root',
183       :logoutput   => 'on_failure',
184     })
185     }
186   end
187
188   describe 'apt included, proxy host' do
189     let :pre_condition do
190       'class { "apt":
191         proxy => { "host" => "localhost" },
192       }'
193     end
194     let :facts do
195       {
196         :lsbdistrelease  => '14.04',
197         :lsbdistcodename => 'trusty',
198         :operatingsystem => 'Ubuntu',
199         :lsbdistid       => 'Ubuntu',
200         :osfamily        => 'Debian',
201         :puppetversion   => Puppet.version,
202       }
203     end
204     let :params do
205       {
206         'options' => '',
207         'package_manage' => true,
208       }
209     end
210     let(:title) { 'ppa:foo' }
211     it { is_expected.to contain_package('software-properties-common') }
212     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
213       :environment => ['http_proxy=http://localhost:8080'],
214       :command     => '/usr/bin/add-apt-repository  ppa:foo',
215       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
216       :user        => 'root',
217       :logoutput   => 'on_failure',
218     })
219     }
220   end
221
222   describe 'apt included, proxy host and port' do
223     let :pre_condition do
224       'class { "apt":
225         proxy => { "host" => "localhost", "port" => 8180 },
226       }'
227     end
228     let :facts do
229       {
230         :lsbdistrelease  => '14.04',
231         :lsbdistcodename => 'trusty',
232         :operatingsystem => 'Ubuntu',
233         :lsbdistid       => 'Ubuntu',
234         :osfamily        => 'Debian',
235         :puppetversion   => Puppet.version,
236       }
237     end
238     let :params do
239       {
240         :options => '',
241         :package_manage => true,
242       }
243     end
244     let(:title) { 'ppa:foo' }
245     it { is_expected.to contain_package('software-properties-common') }
246     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
247       :environment => ['http_proxy=http://localhost:8180'],
248       :command     => '/usr/bin/add-apt-repository  ppa:foo',
249       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
250       :user        => 'root',
251       :logoutput   => 'on_failure',
252     })
253     }
254   end
255
256   describe 'apt included, proxy host and port and https' do
257     let :pre_condition do
258       'class { "apt":
259         proxy => { "host" => "localhost", "port" => 8180, "https" => true },
260       }'
261     end
262     let :facts do
263       {
264         :lsbdistrelease  => '14.04',
265         :lsbdistcodename => 'trusty',
266         :operatingsystem => 'Ubuntu',
267         :lsbdistid       => 'Ubuntu',
268         :osfamily        => 'Debian',
269         :puppetversion   => Puppet.version,
270       }
271     end
272     let :params do
273       {
274         :options => '',
275         :package_manage => true,
276       }
277     end
278     let(:title) { 'ppa:foo' }
279     it { is_expected.to contain_package('software-properties-common') }
280     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
281       :environment => ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'],
282       :command     => '/usr/bin/add-apt-repository  ppa:foo',
283       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
284       :user        => 'root',
285       :logoutput   => 'on_failure',
286     })
287     }
288   end
289
290   describe 'ensure absent' do
291     let :pre_condition do
292       'class { "apt": }'
293     end
294     let :facts do
295       {
296         :lsbdistrelease  => '14.04',
297         :lsbdistcodename => 'trusty',
298         :operatingsystem => 'Ubuntu',
299         :lsbdistid       => 'Ubuntu',
300         :osfamily        => 'Debian',
301         :puppetversion   => Puppet.version,
302       }
303     end
304     let(:title) { 'ppa:foo' }
305     let :params do
306       {
307         :ensure => 'absent'
308       }
309     end
310     it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Class[Apt::Update]').with({
311       :ensure => 'absent',
312     })
313     }
314   end
315
316   context 'validation' do
317     describe 'no release' do
318       let :facts do
319         {
320           :lsbdistrelease  => '14.04',
321           :operatingsystem => 'Ubuntu',
322           :lsbdistid       => 'Ubuntu',
323           :osfamily        => 'Debian',
324           :lsbdistcodeanme => nil,
325           :puppetversion   => Puppet.version,
326         }
327       end
328       let(:title) { 'ppa:foo' }
329       it do
330         expect {
331           subject.call
332         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
333       end
334     end
335
336     describe 'not ubuntu' do
337       let :facts do
338         {
339           :lsbdistrelease  => '6.0.7',
340           :lsbdistcodename => 'wheezy',
341           :operatingsystem => 'Debian',
342           :lsbdistid       => 'debian',
343           :osfamily        => 'Debian',
344           :puppetversion   => Puppet.version,
345         }
346       end
347       let(:title) { 'ppa:foo' }
348       it do
349         expect {
350           subject.call
351         }.to raise_error(Puppet::Error, /not currently supported on Debian/)
352       end
353     end
354   end
355 end