Merge remote-tracking branch 'upstream/master' into merge_master_to_2.1.x
[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' }
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').that_notifies('Class[Apt::Update]').with({
22       :environment => [],
23       :command     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
24       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-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 => false' do
76     let :pre_condition do
77       'class { "apt": }'
78     end
79     let :facts do
80       {
81         :lsbdistrelease  => '11.04',
82         :lsbdistcodename => 'natty',
83         :operatingsystem => 'Ubuntu',
84         :osfamily        => 'Debian',
85         :lsbdistid       => 'Ubuntu',
86         :puppetversion   => Puppet.version,
87       }
88     end
89     let :params do
90       {
91         :package_manage => false,
92       }
93     end
94
95     let(:title) { 'ppa:needs/such.substitution/wow' }
96     it { is_expected.to_not contain_package('python-software-properties') }
97     it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with({
98       'environment' => [],
99       'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
100       'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
101       'user'        => 'root',
102       'logoutput'   => 'on_failure',
103     })
104     }
105
106     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({
107       'ensure' => 'file',
108     })
109     }
110   end
111
112   describe 'apt included, no proxy' do
113     let :pre_condition do
114       'class { "apt": }
115       apt::ppa { "ppa:foo2": }
116       '
117     end
118     let :facts do
119       {
120         :lsbdistrelease  => '14.04',
121         :lsbdistcodename => 'trusty',
122         :operatingsystem => 'Ubuntu',
123         :lsbdistid       => 'Ubuntu',
124         :osfamily        => 'Debian',
125         :puppetversion   => Puppet.version,
126       }
127     end
128     let :params do
129       {
130         :options        => '',
131         :package_manage => true,
132         :require        => 'Apt::Ppa[ppa:foo2]',
133       }
134     end
135     let(:title) { 'ppa:foo' }
136     it { is_expected.to compile.with_all_deps }
137     it { is_expected.to contain_package('software-properties-common') }
138     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
139       :environment => [],
140       :command     => '/usr/bin/add-apt-repository  ppa:foo',
141       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
142       :user        => 'root',
143       :logoutput   => 'on_failure',
144     })
145     }
146   end
147
148   describe 'apt included, proxy host' do
149     let :pre_condition do
150       'class { "apt":
151         proxy => { "host" => "localhost" },
152       }'
153     end
154     let :facts do
155       {
156         :lsbdistrelease  => '14.04',
157         :lsbdistcodename => 'trusty',
158         :operatingsystem => 'Ubuntu',
159         :lsbdistid       => 'Ubuntu',
160         :osfamily        => 'Debian',
161         :puppetversion   => Puppet.version,
162       }
163     end
164     let :params do
165       {
166         'options' => '',
167         'package_manage' => true,
168       }
169     end
170     let(:title) { 'ppa:foo' }
171     it { is_expected.to contain_package('software-properties-common') }
172     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
173       :environment => ['http_proxy=http://localhost:8080'],
174       :command     => '/usr/bin/add-apt-repository  ppa:foo',
175       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
176       :user        => 'root',
177       :logoutput   => 'on_failure',
178     })
179     }
180   end
181
182   describe 'apt included, proxy host and port' do
183     let :pre_condition do
184       'class { "apt":
185         proxy => { "host" => "localhost", "port" => 8180 },
186       }'
187     end
188     let :facts do
189       {
190         :lsbdistrelease  => '14.04',
191         :lsbdistcodename => 'trusty',
192         :operatingsystem => 'Ubuntu',
193         :lsbdistid       => 'Ubuntu',
194         :osfamily        => 'Debian',
195         :puppetversion   => Puppet.version,
196       }
197     end
198     let :params do
199       {
200         :options => '',
201         :package_manage => true,
202       }
203     end
204     let(:title) { 'ppa:foo' }
205     it { is_expected.to contain_package('software-properties-common') }
206     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
207       :environment => ['http_proxy=http://localhost:8180'],
208       :command     => '/usr/bin/add-apt-repository  ppa:foo',
209       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
210       :user        => 'root',
211       :logoutput   => 'on_failure',
212     })
213     }
214   end
215
216   describe 'apt included, proxy host and port and https' do
217     let :pre_condition do
218       'class { "apt":
219         proxy => { "host" => "localhost", "port" => 8180, "https" => true },
220       }'
221     end
222     let :facts do
223       {
224         :lsbdistrelease  => '14.04',
225         :lsbdistcodename => 'trusty',
226         :operatingsystem => 'Ubuntu',
227         :lsbdistid       => 'Ubuntu',
228         :osfamily        => 'Debian',
229         :puppetversion   => Puppet.version,
230       }
231     end
232     let :params do
233       {
234         :options => '',
235         :package_manage => true,
236       }
237     end
238     let(:title) { 'ppa:foo' }
239     it { is_expected.to contain_package('software-properties-common') }
240     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
241       :environment => ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'],
242       :command     => '/usr/bin/add-apt-repository  ppa:foo',
243       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
244       :user        => 'root',
245       :logoutput   => 'on_failure',
246     })
247     }
248   end
249
250   describe 'ensure absent' do
251     let :pre_condition do
252       'class { "apt": }'
253     end
254     let :facts do
255       {
256         :lsbdistrelease  => '14.04',
257         :lsbdistcodename => 'trusty',
258         :operatingsystem => 'Ubuntu',
259         :lsbdistid       => 'Ubuntu',
260         :osfamily        => 'Debian',
261         :puppetversion   => Puppet.version,
262       }
263     end
264     let(:title) { 'ppa:foo' }
265     let :params do
266       {
267         :ensure => 'absent'
268       }
269     end
270     it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Class[Apt::Update]').with({
271       :ensure => 'absent',
272     })
273     }
274   end
275
276   context 'validation' do
277     describe 'no release' do
278       let :facts do
279         {
280           :lsbdistrelease  => '14.04',
281           :operatingsystem => 'Ubuntu',
282           :lsbdistid       => 'Ubuntu',
283           :osfamily        => 'Debian',
284           :lsbdistcodeanme => nil,
285           :puppetversion   => Puppet.version,
286         }
287       end
288       let(:title) { 'ppa:foo' }
289       it do
290         expect {
291           subject.call
292         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
293       end
294     end
295
296     describe 'not ubuntu' do
297       let :facts do
298         {
299           :lsbdistrelease  => '6.0.7',
300           :lsbdistcodename => 'wheezy',
301           :operatingsystem => 'Debian',
302           :lsbdistid       => 'debian',
303           :osfamily        => 'Debian',
304           :puppetversion   => Puppet.version,
305         }
306       end
307       let(:title) { 'ppa:foo' }
308       it do
309         expect {
310           subject.call
311         }.to raise_error(Puppet::Error, /not currently supported on Debian/)
312       end
313     end
314   end
315 end