|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | require 'spec_helper'
|
| 4 | + |
| 5 | +def ppa_exec_params(user, repo, distro = 'trusty', environment = []) |
| 6 | + [ |
| 7 | + environment: environment, |
| 8 | + command: "/opt/puppetlabs/puppet/cache/add-apt-repository-#{user}-ubuntu-#{repo}-#{distro}.sh", |
| 9 | + logoutput: 'on_failure', |
| 10 | + ] |
| 11 | +end |
| 12 | + |
4 | 13 | describe 'apt::ppa' do
|
5 | 14 | let :pre_condition do
|
6 | 15 | 'class { "apt": }'
|
|
24 | 33 | }
|
25 | 34 | end
|
26 | 35 |
|
27 |
| - let(:title) { 'ppa:needs/such.substitution/wow+type' } |
| 36 | + let(:title) { 'ppa:needs/substitution' } |
28 | 37 |
|
29 | 38 | it { is_expected.not_to contain_package('python-software-properties') }
|
30 | 39 | it {
|
31 |
| - is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow+type').that_notifies('Class[Apt::Update]').with(environment: [], |
32 |
| - command: '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type || (rm /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow_type-trusty.list && false)', # rubocop:disable Layout/LineLength |
33 |
| - unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow_type-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs_ubuntu_such_substitution-wow_type.gpg', # rubocop:disable Layout/LineLength |
34 |
| - user: 'root', |
35 |
| - logoutput: 'on_failure') |
| 40 | + is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') |
| 41 | + .that_notifies('Class[Apt::Update]') |
| 42 | + .with(*ppa_exec_params('needs', 'substitution')) |
36 | 43 | }
|
37 | 44 | end
|
38 | 45 |
|
|
57 | 64 | let(:title) { 'ppa:user/foo' }
|
58 | 65 |
|
59 | 66 | it {
|
60 |
| - is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: [], |
61 |
| - command: '/usr/bin/add-apt-repository -y ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && false)', # rubocop:disable Layout/LineLength |
62 |
| - 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 Layout/LineLength |
63 |
| - user: 'root', |
64 |
| - logoutput: 'on_failure') |
| 67 | + is_expected.to contain_exec('add-apt-repository-ppa:user/foo') |
| 68 | + .that_notifies('Class[Apt::Update]') |
| 69 | + .with(*ppa_exec_params('user', 'foo', 'wily')) |
65 | 70 | }
|
66 | 71 | end
|
67 | 72 |
|
68 | 73 | describe 'package_name => software-properties-common' do
|
69 | 74 | let :pre_condition do
|
70 | 75 | 'class { "apt": }'
|
71 | 76 | end
|
| 77 | + |
72 | 78 | let :params do
|
73 | 79 | {
|
74 | 80 | package_name: 'software-properties-common',
|
75 | 81 | package_manage: true,
|
76 | 82 | }
|
77 | 83 | end
|
| 84 | + |
78 | 85 | let :facts do
|
79 | 86 | {
|
80 | 87 | os: {
|
|
92 | 99 | }
|
93 | 100 | end
|
94 | 101 |
|
95 |
| - let(:title) { 'ppa:needs/such.substitution/wow' } |
| 102 | + let(:title) { 'ppa:needs/substitution' } |
96 | 103 |
|
97 | 104 | it { is_expected.to contain_package('software-properties-common') }
|
98 | 105 | it {
|
99 |
| - is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [], |
100 |
| - 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow || (rm /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list && false)', # rubocop:disable Layout/LineLength |
101 |
| - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs_ubuntu_such_substitution-wow.gpg', # rubocop:disable Layout/LineLength |
102 |
| - 'user' => 'root', |
103 |
| - 'logoutput' => 'on_failure') |
104 |
| - } |
105 |
| - |
106 |
| - it { |
107 |
| - is_expected.to contain_file('/etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with('ensure' => 'file') # rubocop:disable Layout/LineLength |
| 106 | + is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') |
| 107 | + .that_notifies('Class[Apt::Update]') |
| 108 | + .with(*ppa_exec_params('needs', 'substitution')) |
108 | 109 | }
|
109 | 110 | end
|
110 | 111 |
|
111 | 112 | describe 'package_manage => false' do
|
112 | 113 | let :pre_condition do
|
113 | 114 | 'class { "apt": }'
|
114 | 115 | end
|
| 116 | + |
115 | 117 | let :facts do
|
116 | 118 | {
|
117 | 119 | os: {
|
|
128 | 130 | },
|
129 | 131 | }
|
130 | 132 | end
|
| 133 | + |
131 | 134 | let :params do
|
132 | 135 | {
|
133 | 136 | package_manage: false,
|
134 | 137 | }
|
135 | 138 | end
|
136 | 139 |
|
137 |
| - let(:title) { 'ppa:needs/such.substitution/wow' } |
| 140 | + let(:title) { 'ppa:needs/substitution' } |
138 | 141 |
|
139 | 142 | it { is_expected.not_to contain_package('python-software-properties') }
|
140 | 143 | it {
|
141 |
| - is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [], |
142 |
| - 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow || (rm /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list && false)', # rubocop:disable Layout/LineLength |
143 |
| - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs_ubuntu_such_substitution-wow.gpg', # rubocop:disable Layout/LineLength |
144 |
| - 'user' => 'root', |
145 |
| - 'logoutput' => 'on_failure') |
146 |
| - } |
147 |
| - |
148 |
| - it { |
149 |
| - is_expected.to contain_file('/etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with('ensure' => 'file') # rubocop:disable Layout/LineLength |
| 144 | + is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') |
| 145 | + .that_notifies('Class[Apt::Update]') |
| 146 | + .with(*ppa_exec_params('needs', 'substitution')) |
150 | 147 | }
|
151 | 148 | end
|
152 | 149 |
|
|
156 | 153 | apt::ppa { "ppa:user/foo2": }
|
157 | 154 | '
|
158 | 155 | end
|
| 156 | + |
159 | 157 | let :facts do
|
160 | 158 | {
|
161 | 159 | os: {
|
|
172 | 170 | },
|
173 | 171 | }
|
174 | 172 | end
|
| 173 | + |
175 | 174 | let :params do
|
176 | 175 | {
|
177 |
| - options: '', |
178 | 176 | package_manage: true,
|
179 | 177 | require: 'Apt::Ppa[ppa:user/foo2]',
|
180 | 178 | }
|
181 | 179 | end
|
| 180 | + |
182 | 181 | let(:title) { 'ppa:user/foo' }
|
183 | 182 |
|
184 | 183 | it { is_expected.to compile.with_all_deps }
|
185 | 184 | it { is_expected.to contain_package('software-properties-common') }
|
186 | 185 | it {
|
187 |
| - is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: [], |
188 |
| - command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && false)', # rubocop:disable Layout/LineLength |
189 |
| - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Layout/LineLength |
190 |
| - user: 'root', |
191 |
| - logoutput: 'on_failure') |
| 186 | + is_expected.to contain_exec('add-apt-repository-ppa:user/foo') |
| 187 | + .that_notifies('Class[Apt::Update]') |
| 188 | + .with(*ppa_exec_params('user', 'foo')) |
192 | 189 | }
|
193 | 190 | end
|
194 | 191 |
|
|
198 | 195 | proxy => { "host" => "localhost" },
|
199 | 196 | }'
|
200 | 197 | end
|
| 198 | + |
201 | 199 | let :facts do
|
202 | 200 | {
|
203 | 201 | os: {
|
|
214 | 212 | },
|
215 | 213 | }
|
216 | 214 | end
|
| 215 | + |
217 | 216 | let :params do
|
218 | 217 | {
|
219 |
| - 'options' => '', |
220 | 218 | 'package_manage' => true,
|
221 | 219 | }
|
222 | 220 | end
|
| 221 | + |
223 | 222 | let(:title) { 'ppa:user/foo' }
|
224 | 223 |
|
225 | 224 | it { is_expected.to contain_package('software-properties-common') }
|
226 | 225 | it {
|
227 |
| - is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8080'], |
228 |
| - command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && false)', # rubocop:disable Layout/LineLength |
229 |
| - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Layout/LineLength |
230 |
| - user: 'root', |
231 |
| - logoutput: 'on_failure') |
| 226 | + is_expected.to contain_exec('add-apt-repository-ppa:user/foo') |
| 227 | + .that_notifies('Class[Apt::Update]') |
| 228 | + .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8080'])) |
232 | 229 | }
|
233 | 230 | end
|
234 | 231 |
|
|
238 | 235 | proxy => { "host" => "localhost", "port" => 8180 },
|
239 | 236 | }'
|
240 | 237 | end
|
| 238 | + |
241 | 239 | let :facts do
|
242 | 240 | {
|
243 | 241 | os: {
|
|
254 | 252 | },
|
255 | 253 | }
|
256 | 254 | end
|
| 255 | + |
257 | 256 | let :params do
|
258 | 257 | {
|
259 |
| - options: '', |
260 | 258 | package_manage: true,
|
261 | 259 | }
|
262 | 260 | end
|
| 261 | + |
263 | 262 | let(:title) { 'ppa:user/foo' }
|
264 | 263 |
|
265 | 264 | it { is_expected.to contain_package('software-properties-common') }
|
266 | 265 | it {
|
267 |
| - is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8180'], |
268 |
| - command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && false)', # rubocop:disable Layout/LineLength |
269 |
| - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Layout/LineLength |
270 |
| - user: 'root', |
271 |
| - logoutput: 'on_failure') |
| 266 | + is_expected.to contain_exec('add-apt-repository-ppa:user/foo') |
| 267 | + .that_notifies('Class[Apt::Update]') |
| 268 | + .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180'])) |
272 | 269 | }
|
273 | 270 | end
|
274 | 271 |
|
|
278 | 275 | proxy => { "host" => "localhost", "port" => 8180, "https" => true },
|
279 | 276 | }'
|
280 | 277 | end
|
| 278 | + |
281 | 279 | let :facts do
|
282 | 280 | {
|
283 | 281 | os: {
|
|
294 | 292 | },
|
295 | 293 | }
|
296 | 294 | end
|
| 295 | + |
297 | 296 | let :params do
|
298 | 297 | {
|
299 |
| - options: '', |
300 | 298 | package_manage: true,
|
301 | 299 | }
|
302 | 300 | end
|
| 301 | + |
303 | 302 | let(:title) { 'ppa:user/foo' }
|
304 | 303 |
|
305 | 304 | it { is_expected.to contain_package('software-properties-common') }
|
306 | 305 | it {
|
307 |
| - 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'], |
308 |
| - command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && false)', # rubocop:disable Layout/LineLength |
309 |
| - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Layout/LineLength |
310 |
| - user: 'root', |
311 |
| - logoutput: 'on_failure') |
| 306 | + is_expected.to contain_exec('add-apt-repository-ppa:user/foo') |
| 307 | + .that_notifies('Class[Apt::Update]') |
| 308 | + .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'])) |
312 | 309 | }
|
313 | 310 | end
|
314 | 311 |
|
315 | 312 | describe 'ensure absent' do
|
316 | 313 | let :pre_condition do
|
317 | 314 | 'class { "apt": }'
|
318 | 315 | end
|
| 316 | + |
319 | 317 | let :facts do
|
320 | 318 | {
|
321 | 319 | os: {
|
|
332 | 330 | },
|
333 | 331 | }
|
334 | 332 | end
|
| 333 | + |
335 | 334 | let(:title) { 'ppa:user/foo' }
|
| 335 | + |
336 | 336 | let :params do
|
337 | 337 | {
|
338 | 338 | ensure: 'absent',
|
339 | 339 | }
|
340 | 340 | end
|
341 | 341 |
|
342 | 342 | it {
|
343 |
| - is_expected.to contain_file('/etc/apt/sources.list.d/user-ubuntu-foo-trusty.list').that_notifies('Class[Apt::Update]').with(ensure: 'absent') |
| 343 | + is_expected.to contain_tidy("remove-apt-repository-script-#{title}") |
| 344 | + .with('path' => '/opt/puppetlabs/puppet/cache/add-apt-repository-user-ubuntu-foo-trusty.sh') |
| 345 | + |
| 346 | + is_expected.to contain_tidy("remove-apt-repository-#{title}") |
| 347 | + .with('path' => '/etc/apt/sources.list.d/user-ubuntu-foo-trusty.list') |
| 348 | + .that_notifies('Class[Apt::Update]') |
344 | 349 | }
|
345 | 350 | end
|
346 | 351 |
|
|
362 | 367 | },
|
363 | 368 | }
|
364 | 369 | end
|
| 370 | + |
365 | 371 | let(:title) { 'ppa:user/foo' }
|
366 | 372 |
|
367 | 373 | it do
|
|
386 | 392 | },
|
387 | 393 | }
|
388 | 394 | end
|
| 395 | + |
389 | 396 | let(:title) { 'ppa:user/foo' }
|
390 | 397 |
|
391 | 398 | it do
|
|
0 commit comments