7903e470377410d2df8320148c066970bb331445
[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       }
16     end
17
18     let(:title) { 'ppa:needs/such.substitution/wow' }
19     it { is_expected.to_not contain_package('python-software-properties') }
20     it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
21       :environment => [],
22       :command     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
23       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
24       :user        => 'root',
25       :logoutput   => 'on_failure',
26     })
27     }
28   end
29
30   describe 'ppa depending on ppa, MODULES-1156' do
31     let :pre_condition do
32       'class { "apt": }'
33     end
34   end
35
36   describe 'package_name => software-properties-common' do
37     let :pre_condition do
38       'class { "apt": }'
39     end
40     let :params do
41       {
42         :package_name   => 'software-properties-common',
43         :package_manage => true,
44       }
45     end
46     let :facts do
47       {
48         :lsbdistrelease  => '11.04',
49         :lsbdistcodename => 'natty',
50         :operatingsystem => 'Ubuntu',
51         :osfamily        => 'Debian',
52         :lsbdistid       => 'Ubuntu',
53       }
54     end
55
56     let(:title) { 'ppa:needs/such.substitution/wow' }
57     it { is_expected.to contain_package('software-properties-common') }
58     it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
59       'environment' => [],
60       'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
61       'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
62       'user'        => 'root',
63       'logoutput'   => 'on_failure',
64     })
65     }
66
67     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({
68       'ensure' => 'file',
69     })
70     }
71   end
72
73   describe 'package_manage => false' do
74     let :pre_condition do
75       'class { "apt": }'
76     end
77     let :facts do
78       {
79         :lsbdistrelease  => '11.04',
80         :lsbdistcodename => 'natty',
81         :operatingsystem => 'Ubuntu',
82         :osfamily        => 'Debian',
83         :lsbdistid       => 'Ubuntu',
84       }
85     end
86     let :params do
87       {
88         :package_manage => false,
89       }
90     end
91
92     let(:title) { 'ppa:needs/such.substitution/wow' }
93     it { is_expected.to_not contain_package('python-software-properties') }
94     it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
95       'environment' => [],
96       'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
97       'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
98       'user'        => 'root',
99       'logoutput'   => 'on_failure',
100     })
101     }
102
103     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({
104       'ensure' => 'file',
105     })
106     }
107   end
108
109   describe 'apt included, no proxy' do
110     let :pre_condition do
111       'class { "apt": }
112       apt::ppa { "ppa:foo2": }
113       '
114     end
115     let :facts do
116       {
117         :lsbdistrelease  => '14.04',
118         :lsbdistcodename => 'trusty',
119         :operatingsystem => 'Ubuntu',
120         :lsbdistid       => 'Ubuntu',
121         :osfamily        => 'Debian',
122       }
123     end
124     let :params do
125       {
126         :options        => '',
127         :package_manage => true,
128         :require        => 'Apt::Ppa[ppa:foo2]',
129       }
130     end
131     let(:title) { 'ppa:foo' }
132     it { is_expected.to compile.with_all_deps }
133     it { is_expected.to contain_package('software-properties-common') }
134     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
135       :environment => [],
136       :command     => '/usr/bin/add-apt-repository  ppa:foo',
137       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
138       :user        => 'root',
139       :logoutput   => 'on_failure',
140     })
141     }
142   end
143
144   describe 'apt included, proxy host' do
145     let :pre_condition do
146       'class { "apt":
147         proxy => { "host" => "localhost" },
148       }'
149     end
150     let :facts do
151       {
152         :lsbdistrelease  => '14.04',
153         :lsbdistcodename => 'trusty',
154         :operatingsystem => 'Ubuntu',
155         :lsbdistid       => 'Ubuntu',
156         :osfamily        => 'Debian',
157       }
158     end
159     let :params do
160       {
161         'options' => '',
162         'package_manage' => true,
163       }
164     end
165     let(:title) { 'ppa:foo' }
166     it { is_expected.to contain_package('software-properties-common') }
167     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
168       :environment => ['http_proxy=http://localhost:8080'],
169       :command     => '/usr/bin/add-apt-repository  ppa:foo',
170       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
171       :user        => 'root',
172       :logoutput   => 'on_failure',
173     })
174     }
175   end
176
177   describe 'apt included, proxy host and port' do
178     let :pre_condition do
179       'class { "apt":
180         proxy => { "host" => "localhost", "port" => 8180 },
181       }'
182     end
183     let :facts do
184       {
185         :lsbdistrelease  => '14.04',
186         :lsbdistcodename => 'trusty',
187         :operatingsystem => 'Ubuntu',
188         :lsbdistid       => 'Ubuntu',
189         :osfamily        => 'Debian',
190       }
191     end
192     let :params do
193       {
194         :options => '',
195         :package_manage => true,
196       }
197     end
198     let(:title) { 'ppa:foo' }
199     it { is_expected.to contain_package('software-properties-common') }
200     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
201       :environment => ['http_proxy=http://localhost:8180'],
202       :command     => '/usr/bin/add-apt-repository  ppa:foo',
203       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
204       :user        => 'root',
205       :logoutput   => 'on_failure',
206     })
207     }
208   end
209
210   describe 'apt included, proxy host and port and https' do
211     let :pre_condition do
212       'class { "apt":
213         proxy => { "host" => "localhost", "port" => 8180, "https" => true },
214       }'
215     end
216     let :facts do
217       {
218         :lsbdistrelease  => '14.04',
219         :lsbdistcodename => 'trusty',
220         :operatingsystem => 'Ubuntu',
221         :lsbdistid       => 'Ubuntu',
222         :osfamily        => 'Debian',
223       }
224     end
225     let :params do
226       {
227         :options => '',
228         :package_manage => true,
229       }
230     end
231     let(:title) { 'ppa:foo' }
232     it { is_expected.to contain_package('software-properties-common') }
233     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
234       :environment => ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'],
235       :command     => '/usr/bin/add-apt-repository  ppa:foo',
236       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
237       :user        => 'root',
238       :logoutput   => 'on_failure',
239     })
240     }
241   end
242
243   describe 'ensure absent' do
244     let :pre_condition do
245       'class { "apt": }'
246     end
247     let :facts do
248       {
249         :lsbdistrelease  => '14.04',
250         :lsbdistcodename => 'trusty',
251         :operatingsystem => 'Ubuntu',
252         :lsbdistid       => 'Ubuntu',
253         :osfamily        => 'Debian',
254       }
255     end
256     let(:title) { 'ppa:foo' }
257     let :params do
258       {
259         :ensure => 'absent'
260       }
261     end
262     it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({
263       :ensure => 'absent',
264     })
265     }
266   end
267
268   context 'validation' do
269     describe 'no release' do
270       let :facts do
271         {
272           :lsbdistrelease  => '14.04',
273           :operatingsystem => 'Ubuntu',
274           :lsbdistid       => 'Ubuntu',
275           :osfamily        => 'Debian',
276           :lsbdistcodeanme => nil,
277         }
278       end
279       let(:title) { 'ppa:foo' }
280       it do
281         expect {
282           is_expected.to compile
283         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
284       end
285     end
286
287     describe 'not ubuntu' do
288       let :facts do
289         {
290           :lsbdistrelease  => '6.0.7',
291           :lsbdistcodename => 'wheezy',
292           :operatingsystem => 'Debian',
293           :lsbdistid       => 'debian',
294           :osfamily        => 'Debian',
295         }
296       end
297       let(:title) { 'ppa:foo' }
298       it do
299         expect {
300           is_expected.to compile
301         }.to raise_error(Puppet::Error, /supported on Ubuntu and LinuxMint only/)
302       end
303     end
304   end
305 end