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